Moving to node-red-contrib-mongodb4 and I'm having issues.
I can perform a find operation, but I cannot for the life of me pass in any options like $sort or $limit

From a function node, I setup the collection and operations:

msg.collection = "foo";
msg.operation = "find";

I try two types of methods in attempt to implementing the options:

method #1:

 const options = {
     $sort : { "_id" : -1   },
     $limit : 1

msg.payload = [

and this function node passes the msg to a node-red-contrib-mongodb4 node,
which performs the find, but returns all documents.

I've also tried to do so by method of it's processor : node-red-contrib-mongodb (which worked well)
by tacking on the msg object:

method #2:

msg.payload = msg.searchQuery

msg.sort = { "_id" : -1}
msg.limit = 1

return msg;

Still neither of these methods work for me and are still returning the full set of documents, and not limiting the return.

I just can't seem to get these find options to work.
Not sure what I'm doing wrong here.

I was able to do this with an aggregate operation, but the caveat was it needed double brackets??

msg.collection = global.get("db")["submissions"];
msg.operation = "aggregate"

msg.payload =  // Pipeline
        // Stage 1
            $match: {
                // conditional query 
                "season_code": "CODE2021"
        // Stage 2
        {$limit : 1}


This code example produced a working result when passed to the node.

1 Like

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