Merge pull request #26929 from mjomble/mongodb-aggregate

mongodb: improved overloads for Collection.aggregate()
This commit is contained in:
Paul van Brenk
2018-06-28 14:35:49 -07:00
committed by GitHub
2 changed files with 27 additions and 1 deletions
+2 -1
View File
@@ -482,8 +482,9 @@ export interface Collection<TSchema = Default> {
// Get current index hint for collection.
hint: any;
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#aggregate */
aggregate<T = TSchema>(callback: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
aggregate<T = TSchema>(pipeline: Object[], callback: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
aggregate<T = TSchema>(pipeline: Object[], options?: CollectionAggregationOptions, callback?: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
aggregate<T = TSchema>(pipeline?: Object[], options?: CollectionAggregationOptions, callback?: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#bulkWrite */
bulkWrite(operations: Object[], callback: MongoCallback<BulkWriteOpResultObject>): void;
bulkWrite(operations: Object[], options?: CollectionBluckWriteOptions): Promise<BulkWriteOpResultObject>;
+25
View File
@@ -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<payment> = collection.aggregate<payment>([{}])
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<payment>(
[{ $match: { bar: 1 } }],
function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor<payment>) {
cursor.limit(10)
}
)
collection.aggregate<payment>(
[],
function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor<payment>) {
cursor.match({ bar: 1 }).limit(10)
}
)
collection.aggregate<payment>(
function (err: mongodb.MongoError, cursor: mongodb.AggregationCursor<payment>) {
cursor.match({ bar: 1 }).limit(10)
}
)
}
// test for new typings