Method "collection.aggregate()" accepts at most two arguments
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
Error: Method "collection.aggregate()" accepts at most two arguments
MongoInvalidArgumentError: Method "collection.aggregate()" accepts at most two arguments
at Collection.aggregate (/home/dave/projects/asd/node_modules/mongodb/lib/collection.js:367:19)
at NativeCollection.<computed> [as aggregate] (/home/dave/projects/asd/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:200:33)
at NativeCollection.Collection.doQueue (/home/dave/projects/asd/node_modules/mongoose/lib/collection.js:135:23)
at /home/dave/projects/asd/node_modules/mongoose/lib/collection.js:82:24
at processTicksAndRejections (internal/process/task_queues.js:77:11)
If the current behavior is a bug, please provide the steps to reproduce.
import Client from '../models/client';
...
const clients = await Client.aggregate([
{ $match: { active: true } },
{ $project: {
name: 1,
image: 1,
maxContract: {
$arrayElemAt: [ '$contracts', { $indexOfArray: ['$contracts.endDate', { $max: '$contracts.endDate' }] } ]
}
}
},
{ $match: { 'maxContract.endDate': { $lte: date, $gte: new Date() } } },
{ $sort: { 'maxContract.endDate': 1 } }
]);
Happens also with a simple match query inside aggregate:
import Client from '../models/client';
...
const clients = await Client.aggregate([
{ $match: { active: true } }
]);
What is the expected behavior? Working as v5?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. Node: v14.17.6, Mongoose: v6.0.5, TypeScript: v4.2.4
I have this error since v6, it’s working fine with v5. I can’t find where the breaking change is documented tbh… Any help is appreciated, thanks.
Also, TypeScript aggregate signature is:
(method) Model<IClient, {}, {}>.aggregate<any>(pipeline?: any[]): Aggregate<any[]> (+1 overload)
But if the arguments must be different, TypeScript should tell before compiling.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:10 (2 by maintainers)
Top Results From Across the Web
MongoDB collection.aggregrate accept only two arguments
When I run that aggregation, it show the error. What am I missing? const data = await Rooms.aggregate([{ $match: { ...
Read more >[GraphQL error]: Method "collection.aggregate()" accepts at ...
[GraphQL error]: Method "collection.aggregate()" accepts at most two arguments The app uses aldeed:collection2 and …
Read more >db.collection.aggregate()
See the aggregation pipeline operators for details. The method can still accept the pipeline stages as separate arguments instead of as elements in...
Read more >Lesson 3: Introducing the MongoDB aggregate method
This is followed by the aggregate method and its two arguments, as indicated by the pipeline and options placeholders.
Read more >How To Use Aggregations in MongoDB
The aggregate() method executed on the cities collection instructs MongoDB to run an aggregation pipeline passed as the method argument. Because ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Confirmed this bug, fix will be in 6.0.7 on Monday 👍
Modify script below to reproduce your error and I will try again.