Closed RafOXxxx closed 6 years ago
Install mongodb and use mongodb.ObjectId()
. Maybe { "$id": "..." }
will also work but I'm not sure.
Thanks for the response, the { "$id": "..." }
approach did not work for me.
I installed node-red-contrib-objectid, that made it work.
Are there newer example-flows for node-red-contrib-mongodb2? Because I also have trouble sorting my results. In examples I have seen so far people just do:
msg.sort = { time: -1 }
but that does not seem to work anymore.
Great, I didn't know node-red-contrib-objectid exists. I just install mongodb and use const { ObjectId } = require('mongodb');
.
node-red-contrib-mongodb2 only looks at the msg.payload param - which should be an array of arguments that are passed to the mongodb operations. For example, the find operation can accept two parameters: query
and options
. In options you can use "sort", so you may want to create a msg with a payload that looks like:
[{ somequeryfield: somevalue }, { sort: { time: -1 }}]
.
Thank god! I have been googling for this information for a couple of days now and somehow could only find very misleading stuff. I can't thank you enough ozomer! 😃 👍
You're welcome @RafOXxxx !
I am not able to delete documents by "_id" using the
deleteOne()
method. I presume it's because I am passing the id as a string and not as anObjectId
object. But saying that, how do I turn a string into anObjectId
object?