# Node-red-contrib-mongodb4 aggregate not working

**URL:** <https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621>\
**Category:** General\
**Created:** [21 March 2026 22:26 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621 "2026-03-21T22:26:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin1](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@Kevin1](https://discourse.nodered.org/u/Kevin1)\
**Post date:** [21 March 2026 22:26 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621/1 "2026-03-21T22:26:47Z")

</div>

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:

```auto

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;

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [22 March 2026 03:02 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621/2 "2026-03-22T03:02:43Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Kevin1](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@Kevin1](https://discourse.nodered.org/u/Kevin1)\
**Post date:** [22 March 2026 10:17 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621/3 "2026-03-22T10:17:06Z")

</div>

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:

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

msg.payload = [var1, var2]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 June 2026 10:17 UTC](https://discourse.nodered.org/t/node-red-contrib-mongodb4-aggregate-not-working/100621/4 "2026-06-20T10:17:43Z")

</div>

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