How Can Get Newest Document Just Using The Map
I have document like the following, I want to use map function to get the latest status with given UserId doc1: _id=id1, UserId='ABC', status='OPEN',... doc2: _id=id2, UserId='BCD'
Solution 1:
If I understand correctly, you are trying to find all documents and their statuses for the same user ID, that's easy with a following map (example not case sensitive):
emit(doc.userId, doc.status)
then the reduce function could deal with finding the right status (your values will be docs of the same user id, with different statuses so you can loop through them finding the one with closed status or returning open if not found).
Post a Comment for "How Can Get Newest Document Just Using The Map"