mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #26861 from mjomble/mongodb-count
mongodb: improved overloads for Collection.count()
This commit is contained in:
Vendored
+2
-1
@@ -487,8 +487,9 @@ export interface Collection<TSchema = Default> {
|
||||
bulkWrite(operations: Object[], options?: CollectionBluckWriteOptions): Promise<BulkWriteOpResultObject>;
|
||||
bulkWrite(operations: Object[], options: CollectionBluckWriteOptions, callback: MongoCallback<BulkWriteOpResultObject>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#count */
|
||||
count(callback: MongoCallback<number>): void;
|
||||
count(query: Object, callback: MongoCallback<number>): void;
|
||||
count(query: Object, options?: MongoCountPreferences): Promise<number>;
|
||||
count(query?: Object, options?: MongoCountPreferences): Promise<number>;
|
||||
count(query: Object, options: MongoCountPreferences, callback: MongoCallback<number>): void;
|
||||
/** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#createIndex */
|
||||
createIndex(fieldOrSpec: string | any, callback: MongoCallback<string>): void;
|
||||
|
||||
@@ -35,7 +35,29 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function (err: mo
|
||||
var collection = db.collection('test_insert');
|
||||
collection.insertOne({ a: 2 }, function (err: mongodb.MongoError, docs: any) {
|
||||
|
||||
collection.count(function (err: mongodb.MongoError, count: any) {
|
||||
// Intentionally omitted type annotation from 'count'.
|
||||
// This way it requires a more accurate typedef which allows inferring that it's a number.
|
||||
collection.count(function (err: mongodb.MongoError, count) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
collection.count().then(function (count: number) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
collection.count({ foo: 1 }, function (err: mongodb.MongoError, count: number) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
collection.count({ foo: 1 }).then(function (count: number) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
collection.count({ foo: 1 }, { limit: 10 }, function (err: mongodb.MongoError, count: number) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
collection.count({ foo: 1 }, { limit: 10 }).then(function (count: number) {
|
||||
console.log(format("count = %s", count));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user