Node-red-contrib-mongodb4 handle document id error

As it docs says, it supports string id to ObjectId ,

And as I use, the first is ok, that is [{_id: "624b527d08e23628e99eb963"}]
and the second usage: [{_id: {$in: ["624b527d08e23628e99eb963"]}}], if the array only one items, It's also ok. but if the array has two or more items, only the fo item works.

For example:
Here is my query:


var query={
    _id:{$in:["63ec78c7ee9d600c7c666a11","63e5fe8c029d12ec138189ab"]}
}
var update={
    $set:{
        isDeleted:1
    }
}
msg.payload=[query,update]
return msg;

And after some testing, It's only support one item in this array, and the mongo db operation works only for the first item. And other ids is leave not updated.

Hi. Since this looks like a feature request for a contrib node, you will likely have to raise this with the author of that contrib node (link to repository will likely be in the nodes readme page on NPM) unless the author frequents this forum and sees your comment.

As a temporary workaround (until the node gets updated to support multiple ids)
you can load the mongodb driver in your Function in order to convert to ObjectIds yourself

image

let ObjectId = mongodb.ObjectId

var query={
    _id:{$in:[ObjectId("63ec78c7ee9d600c7c666a11"),ObjectId("63e5fe8c029d12ec138189ab")]}
}
var update={
    $set:{
        isDeleted:1
    }
}
msg.payload=[query,update]
return msg;

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