How to count the number of documents in a mongodb collection

前端 未结 8 2002
广开言路
广开言路 2020-12-29 04:49

I would like to know how to count the number of documents in a collection. I tried the follow

var value = collection.count();
&&
var value = collecti         


        
8条回答
  •  忘掉有多难
    2020-12-29 05:28

    Traverse to the database where your collection resides using the command:

    use databasename;
    

    Then invoke the count() function on the collection in the database.

    var value = db.collection.count();
    

    and then print(value) or simply value, would give you the count of documents in the collection named collection.

    Refer: http://docs.mongodb.org/v2.2/tutorial/getting-started-with-the-mongo-shell/

提交回复
热议问题