Closed Sherulez closed 6 years ago
Looking a little bit I came across this problem of JonSilver #8. (ty 🥇) And indeed, it is necessary to include the projection in the payload like this for example :
myMsg.payload = [{'subject': 'temp'}, {'value' : 1, '_id': 0}];
Yes, msg.payload
should be an array of all the parameters that are passed to find(...)
.
The documentation of mongodb-find does not mention that the function can accept more than one parameter, but it does.
A more "correct" way would be something like:
myMsg.payload = [{"subject": "temp"}, {"fields": {"value": 1, "_id": 0}}];
Because the second parameter is actually an "options" parameter, that can contain many type of options - "fields" for projection, but also others like "skip", "limit", etc.
The "find" function in the mongodb library actually iterates all the keys in the options parameter, and if it detects unfamiliar names it treats the whole options object as "fields" for projection.
Hi,
Does
.projection
work with thefind.toArray
operation?I read here node-mongodb
My function always returns an array with all the fields. (even
_id
). Is it normal ? I can always change the output like this with a new function :But I would like to know if it was possible to limit the fields at the query level ? Thanks in advance.