Answer the question
In order to leave comments, you need to log in
Using the MongoDB projection parser (mongoose, NodeJS)
Good evening.
There is a certain function findUsers(ids, projection, callback){...}
The function accepts a list of user IDs, fields to be selected and, accordingly, a callback.
The function first searches for the specified users in Redis (users are stored serialized in string keys). If there are none, then it gets the missing ones from the mongo, after which it caches them, so that with the next same request, respectively, all these users are already taken from the cache. When contacting the mongo for the missing users, we take the document in full (do not use the projection passed in the second argument), because we will need to put the user in the cache.
Thus, the function glues data from radish and mongi (+ caches). The catch is that before passing the result to the callback, I need to filter them and return only those fields that were requested (via projection, the second argument to the function).
Is it possible to somehow use the native parser that is used inside the .find, findOne methods? Those. feed it my glued result object and projection and have it filter it all out. I need projections like {wishes.$.title: 1} to be handled correctly.
Can you do without your bikes?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question