问题
I want to check one collection's information just like the db.collection.stats() command in origin MongoDB
How can I do it in mongoose on schema or on model?
回答1:
Had the same problem and managed to query it this way:
YourModel.collection.stats(callback);
You basically access a Model's native interface via the collection property (this is not the collection name, but a property in fact called collection). You can then use any native functions on this object.
回答2:
You can run any arbitrary command via executeDbCommand so since stats is just a database command, you can runCommand that stats() does under the hood:
db.runCommand( { collstats : collectionName } );
来源:https://stackoverflow.com/questions/19708421/what-is-the-db-collection-stats-command-in-mongoose