Add MongoDB stats type

This commit is contained in:
Panu Horsmalahti
2015-02-10 15:55:31 +02:00
parent 35fffaa44b
commit 1b8c6b6cf4
2 changed files with 48 additions and 3 deletions

View File

@@ -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");
});
});
})
})

44
mongodb/mongodb.d.ts vendored
View File

@@ -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;
}