What is the db.collection.stats() command in mongoose?

两盒软妹~` 提交于 2019-12-11 02:45:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!