ozomer / node-red-contrib-mongodb2

MongoDB driver node for Node-RED
Apache License 2.0
15 stars 19 forks source link

custom query #36

Closed accateo closed 5 years ago

accateo commented 5 years ago

Hi, i'm using your component "mongodb2" and "mongodb3". I'm having a problem to write this query:

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

that works correctly in a mongo shell. But in your component there are only "aggregate.forEach" and "aggregate.toArray", but not only "aggregate". How can I resolve? Is there a possibility to put my query as string, directly? Thanks

ozomer commented 5 years ago

The aggregate function returns an AggregationCursor which i didn't think would be useful directly in node-red - especially due to the nature of node-red that may clone objects when they are sent as messages. You would typically want to convert the AggregationCursor to an array of results or to iterate the results (i.e. use forEach to send a new message per result).