ozomer / node-red-contrib-mongodb2

MongoDB driver node for Node-RED
Apache License 2.0
15 stars 19 forks source link

msg.projection does not work #27

Closed number005 closed 5 years ago

number005 commented 6 years ago

operation: find.toArray

The function before the mongodb3 node containts:

msg.payload = {"age":50}
msg.projection = {"firstName":1}

return msg;

Anyhow, the result includes all fields and not only the firstName like I wish.

ozomer commented 6 years ago

Try: msg.payload = [{"age": 50}, {"fields": {"firstName": 1}}]; return msg;

Digital-Thor commented 5 years ago

Not sure if the question is for Mongo V3, but according to the V3 Docs, fields is deprecated. I found this structure works for me:

msg.payload =  [
    { age: 50},
    { 
        projection : {firstname: 1},
        limit: 5
    }
];
return msg;

In this case, Mongo should return only the firstname field, for up to a maximum of 5 results.