# MongoDb custom query

**URL:** <https://discourse.nodered.org/t/mongodb-custom-query/8989>\
**Category:** General\
**Created:** [14 March 2019 16:46 UTC](https://discourse.nodered.org/t/mongodb-custom-query/8989 "2019-03-14T16:46:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![accca](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@accca](https://discourse.nodered.org/u/accca)\
**Post date:** [14 March 2019 16:46 UTC](https://discourse.nodered.org/t/mongodb-custom-query/8989/1 "2019-03-14T16:46:33Z")

</div>

Hi,  
I'm new in the world of MongoDb and Node-Red. I have a question.  
I'm using the "mongodb2" component and I would execute an aggregate query, like this:

db.collection.aggregate([{$match:{"id": {$eq: 32823}}}, {"$group" : {\_id:"$zone", count:{$sum:1}}}])

There is any possibility to pass this string to the "mongodb2" component? Or I must set all the component of "msg"? Because I don't know how can I do this, maybe in this way:

msg.payload = {id: msg.payload};  
msg.group = {"value": { \_id: "$zone" }, "count": { "$sum": 1 }};

but it not works, because "mongodb2" has "aggregate.forEach" and "aggregate.toArray"...  
Any idea?

---

<div class="post-metadata">

**Author:** ![apex](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@apex](https://discourse.nodered.org/u/apex)\
**Post date:** [21 April 2020 09:44 UTC](https://discourse.nodered.org/t/mongodb-custom-query/8989/2 "2020-04-21T09:44:43Z")

</div>

hi i want do the same ....  
any update from you?thanks
