diff --git a/mongodb/mongodb-tests.ts b/mongodb/mongodb-tests.ts index 95333f78c..9cd73d073 100644 --- a/mongodb/mongodb-tests.ts +++ b/mongodb/mongodb-tests.ts @@ -21,5 +21,10 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) { // Let's close the db db.close(); }); + + // Get some statistics + collection.stats(function (err, stats) { + console.log(stats.count + " documents"); + }); }); -}) \ No newline at end of file +}) diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index a28f484ce..a1424cb7e 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -253,6 +253,46 @@ declare module "mongodb" { pkFactory?: PKFactory; } + // Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ + export interface CollStats { + // Namespace. + ns: string; + + // Number of documents. + count: number; + + // Collection size in bytes. + size: number; + + // Average object size in bytes. + avgObjSize: number; + + // (Pre)allocated space for the collection in bytes. + storageSize: number; + + // Number of extents (contiguously allocated chunks of datafile space). + numExtents: number; + + // Number of indexes. + nindexes: number; + + // Size of the most recently created extent in bytes. + lastExtentSize: number; + + // Padding can speed up updates if documents grow. + paddingFactor: number; + flags: number; + + // Total index size in bytes. + totalIndexSize: number; + + // Size of specific indexes in bytes. + indexSizes: { + _id_: number; + username: number; + }; + } + // Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html export interface Collection { new (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions): Collection; // is this right? @@ -326,8 +366,8 @@ declare module "mongodb" { indexes(callback: Function): void; aggregate(pipeline: any[], callback: (err: Error, results: any) => void): void; aggregate(pipeline: any[], options: {readPreference: string}, callback: (err: Error, results: any) => void): void; - stats(options: {readPreference: string; scale: number}, callback: Function): void; - stats(callback: (err: Error, results: any) => void): void; + stats(options: {readPreference: string; scale: number}, callback: (err: Error, results: CollStats) => void): void; + stats(callback: (err: Error, results: CollStats) => void): void; hint: any; }