I'm using Node.js and MongoDB and I need to use the functions "find" and "aggregate" togheter. For example:
var mongo = require('mongodb')
mongo.MongoClient.connect(uri, {
useNewUrlParser: true }, function(errorConectDB, client) {
dbo.collection(this._objectName).find(query,options).aggregate(agr).toArray(function(err,
res) {....}) })
However, when I execute my code the following error appears:
TypeError: dbo.collection(...).find(...).aggregate is not a function
Is there any way to fix it? Do you recommend any other alternative?
Use $match
in aggregate
instead of using find
as explained here: https://docs.mongodb.com/manual/reference/operator/aggregation/match/
For example:
db.articles.aggregate(
[ { $match : { author : "dave" } } ]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With