Mongodb3 sort command to find maximum value

Hi,
I am unable to understand, the functioning of mongodb3 package.

I am trying to get max value , using following.

msg.operation="findOne";
msg.sort={_id:-1};
msg.limit=1;
return msg;

However this command runs perfectly in mongodb -

db.test.find().sort({_id:-1}).limit(1)

return object having maximum value of _id field.

So , please let me know, what will be equivalent of the above command in mongodb3.

Flow Code

[{"id":"a6d9fe15.99d25","type":"debug","z":"e26eb468.a89b88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1010,"y":120,"wires":[]},{"id":"dc464732.061828","type":"inject","z":"e26eb468.a89b88","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":"5","x":270,"y":120,"wires":[["2398a2b2.eab52e"]]},{"id":"2398a2b2.eab52e","type":"function","z":"e26eb468.a89b88","name":"","func":"msg.operation=\"findOne\";\nmsg.sort={_id:-1};\nmsg.limit=1;\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":120,"wires":[["86169ef4.09f28"]]},{"id":"86169ef4.09f28","type":"mongodb3 in","z":"e26eb468.a89b88","service":"_ext_","configNode":"63723592.a6addc","name":"","collection":"test","operation":"","x":720,"y":120,"wires":[["a6d9fe15.99d25"]]},{"id":"63723592.a6addc","type":"mongodb3","z":"","uri":"mongodb://localhost:27017/machine","name":"","options":"","parallelism":"-1"}]

Also

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.