Problem use aggregate with mongodb3

Hi I try to use aggregate in mongodb3 node but result not true

my flow

[
    {
        "id": "b583c2b096c05a21",
        "type": "mongodb3 in",
        "z": "d851478c2fe7e179",
        "service": "_ext_",
        "configNode": "f0ce3a84bbff14f4",
        "name": "",
        "collection": "",
        "operation": "aggregate.toArray",
        "x": 610,
        "y": 400,
        "wires": [
            [
                "9f3fcdcb4a825e8d"
            ]
        ]
    },
    {
        "id": "c759e5a57184164f",
        "type": "function",
        "z": "d851478c2fe7e179",
        "name": "",
        "func": "const date1 = new Date('2022-06-20 16:06:00');\nconst date2 = new Date('2022-06-20 17:05:00')\n\nvar newMsg = {};\nnewMsg.collection = \"markup_5min\";\nnewMsg.payload =[\n        { \n            $match:{\n                datetime : { \n                    $gte:date1, \n                    $lte:date2\n                    \n                },\n                imei:'866416049315865'\n            }\n        },{\n            $group:{\n                _id: \"null\",\n                pulse_for: {$sum:\"$pulse\"},\n                count: {$sum:1}\n            }\n        }\n    ]\n\nreturn newMsg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 400,
        "wires": [
            [
                "b583c2b096c05a21"
            ]
        ]
    },
    {
        "id": "9f3fcdcb4a825e8d",
        "type": "debug",
        "z": "d851478c2fe7e179",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 480,
        "wires": []
    },
    {
        "id": "7ac10671ac811fb5",
        "type": "inject",
        "z": "d851478c2fe7e179",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 400,
        "wires": [
            [
                "c759e5a57184164f"
            ]
        ]
    },
    {
        "id": "f0ce3a84bbff14f4",
        "type": "mongodb3",
        "uri": "mongodb://192.168.1.21,192.168.1.22,192.168.1.23/Master_Data?replicaSet=rs0",
        "name": "Master_Data",
        "options": "",
        "parallelism": "-1"
    }
]

But result in Navicat I use is true

what the problem with my bordered code

Thank

you are right .. there is something wrong with this node's aggregate option

i replaced the node with node-red-node-mongodb and with that the command works fine

looking at the query I feel the problem maybe with the query. The queryneeds to be an array of parts where the first part is the aggregation. Try wrapping the query array in an array like

newMsg.payload =[
        { 
            $match:{
                datetime : { 
                    $gte:date1, 
                    $lte:date2
                    
                },
                imei:'866416049315865'
            }
        },{
            $group:{
                _id: "null",
                pulse_for: {$sum:"$pulse"},
                count: {$sum:1}
            }
        }
    ]

should be

newMsg.payload = [
[
        { 
            $match:{
                datetime : { 
                    $gte:date1, 
                    $lte:date2
                    
                },
                imei:'866416049315865'
            }
        },{
            $group:{
                _id: "null",
                pulse_for: {$sum:"$pulse"},
                count: {$sum:1}
            }
        }
    ]
]

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