inner-query

How to pass inner query in mongodb from javascript

寵の児 提交于 2020-07-09 07:00:10
问题 I want to create an aggregation pipeline which one of the matches use results from other collection (inner query). This is an example: db.users.aggregate([ {"$match":{"id":{"$in":["0","1","2"]},"p": {$in: db.groups.distinct("p", {"enable":true)}}}, {"$group":{"_id":"$v","number":{"$sum":1}}} ]) and i need to do the query from javascript . Actually the application is nodejs with mongoose . Unfortunately when mongoose executes the query i get: MongoError: $in needs an array This is the query