Node-red-contrib-mongodb4 aggregate not working

Hi,

I recently started using node-red and I have some issues with node-red-contrib-mongodb4 and the aggregate operation. I get the following error message : "A pipeline must be an array of objects" code: 14, but when I check the input with the debug note it is clearly an array with multiple objects.

I can't seem to find a solution, as it works without issue in python. Maybe someone else knows, what I am doing wrong.
This is my code for reference:


msg.payload = [
    {
        "$match": {
            "ENG": "ENG"
        }
    },
    {
        "$lookup": {
            "from": "ENG",
            "localField": "Fauf",
            "foreignField": "Prod_Fauf",
            "as": "joinedData"
        }
    },
    
    {
        "$set": {
            "joinedData": { "$first": "$joinedData" }
        }
    },
    {
        "$set": {
            "ENG_ID": "$joinedData.ENG_ID",
            "Reporter": "$joinedData.Reporter"
        }
    },
    {
        "$unset": ["joinedData", "_id"] 
    }

];

return msg;

Hello .. for this node-red-contrib-mongodb4 node you need wrap the query in a second set of square brackets.
For example :

msg.payload = [[
    {
        "$match": {
            "ENG": "ENG"
        }
    }]];

Hi, thank you that acutally worked.
I saw it in the documentation but implemented it differently and it did not work. Didnt even think about doing it like this.

My attempt that did not work for documentation:

const var1 = [
    {
        "$match": {
            "ENG": "ENG"
        }
    }];
const var2= [
    {
        "$lookup": {
            "from": "ENG",
            "localField": "Fauf",
            "foreignField": "Prod_Fauf",
            "as": "joinedData"
        }
    }];

msg.payload = [var1, var2]