diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 12927d1f34..1c13dc4f11 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -482,8 +482,9 @@ export interface Collection { // Get current index hint for collection. hint: any; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#aggregate */ + aggregate(callback: MongoCallback>): AggregationCursor; aggregate(pipeline: Object[], callback: MongoCallback>): AggregationCursor; - aggregate(pipeline: Object[], options?: CollectionAggregationOptions, callback?: MongoCallback>): AggregationCursor; + aggregate(pipeline?: Object[], options?: CollectionAggregationOptions, callback?: MongoCallback>): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#bulkWrite */ bulkWrite(operations: Object[], callback: MongoCallback): void; bulkWrite(operations: Object[], options?: CollectionBluckWriteOptions): Promise; diff --git a/types/mongodb/mongodb-tests.ts b/types/mongodb/mongodb-tests.ts index a5a27bd671..5b6e199be7 100644 --- a/types/mongodb/mongodb-tests.ts +++ b/types/mongodb/mongodb-tests.ts @@ -121,6 +121,31 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function (err: mo let payment: { total: number }; type payment = typeof payment; let cursor: mongodb.AggregationCursor = collection.aggregate([{}]) + + collection.aggregate([{ $match: { bar: 1 } }, { $limit: 10 }]) + collection.aggregate([{ $match: { bar: 1 } }]).limit(10) + collection.aggregate([]).match({ bar: 1 }).limit(10) + collection.aggregate().match({ bar: 1 }).limit(10) + + collection.aggregate( + [{ $match: { bar: 1 } }], + function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor) { + cursor.limit(10) + } + ) + + collection.aggregate( + [], + function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor) { + cursor.match({ bar: 1 }).limit(10) + } + ) + + collection.aggregate( + function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor) { + cursor.match({ bar: 1 }).limit(10) + } + ) } // test for new typings