anuragvohraec opened a new issue #2669: Expose MD5 or some kind of standard 
hash function to be used inside a map function, which will allow easy 
comparsion of deep nested objects ?
URL: https://github.com/apache/couchdb/issues/2669
 
 
   It would be a nice idea to expose some kind of standard hash function [say 
md5], which can be used inside a map function.
   So every emit that is being done like this `emit(**hash(**jsKeyObject**)**, 
someValue);`, will generate a unique hash key, this can make deep nested object 
comparsion very easy and fast, from a view.
   
   ## Summary
   Apart from emit function and other [JS objects provided by couchdb inside 
map 
functions](https://docs.couchdb.org/en/stable/query-server/javascript.html#javascript),
 couchdb can also provide one [many] standard hash functions. For example 
`hashMD5(toJson(someKeyObject))`
   
   This will allow deep object comparison a peice of cake from a view.
    
   ## Desired Behaviour
   ### Usage
   Inside a map function, apart from emit , a `hash(String value)`,  expose a 
JS hash function.
   So we can emit object like :
   `emit(hashMD5(toJson(jsonKeyObject)), someOtherValueIfRequired);`
   
   ## Suggest how to implement the addition or change. 
   A standard toJson and hash function needs to be defined. toJson 
standardization will allow sam hash to be created at client and couch end.
   The specification for both of this function should be clearly be made 
available [just like the replication protocol], so that we can update our couch 
local clients accordingly.
   
   [MD5 hash JS implementations are already 
available.](https://www.npmjs.com/package/md5)
   
   ## Additional context
   #  Why does this feature matter to you? What unique circumstances do you 
have?
   
   I am designing a nodejs solution for user access management system.
   1. I wanted to check if user/user's group has all appropriate rights or not.
   2. Also check if an access group description has changed or not over time.
   
   For example: User will present a json webtoken with an access hash (of 
groups) he thinks he has.
   If that groups has changed over time, its map function will create new 
hashes.
   Just by mere comparing hashes I can ensure user has all proper rights or not.
   
   Now it will be preemptive to think that `toJson` can be used in a smilar 
way, but we are talking about deep nested 8 MB Documents here. [Doc size limit 
in Couch 3.0]. 
   
   So for fast search and match, hash function mapping can be very helpfull.
   Its very easy to implment and will have no effect on existing couch 
functionality.
   
   Please feel free to reach me, if more info requried.
   Can this be part of couchdb 3.0.1 release as its very simple to implment, if 
I am not wrong.
   [I have no knowledge of erlang, but have imeplemented couchdb type of db for 
dart/flutter applications].

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to