How to count the number of documents in a mongodb collection

前端 未结 8 1987
广开言路
广开言路 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:32

    Through MongoDB Console you can see the number of documents in a collection.

    1.Go to mongoDB console and issue command "use databasename". To start the console go up to the bin folder of where MongoDB is installed and click on mongo.exe to start the mongoDB console e.g If the database is myDB then command is "use myDB"

    2.Execute this command db.collection.count() collection is like table in RDBMS. e.g if your collection name is myCollection then the command is db.myCollection.count();

    this command will print the size of the collection in the console.

提交回复
热议问题