- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the max field mean in the output of MongoDB db..stats( )?
Use max field in order to limit the number of documents in the collection. Following is the query to use the max field in the capped collection −
> db.createCollection("demo673", { capped : true, size : 100, max :50 } ) { "ok" : 1 }
Let us create a collection with documents −
> db.demo673.insertOne({Name:"John",Age:23}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3ec7304263e90dac943e8") } > db.demo673.insertOne({Name:"Bob",Age:21}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3ec7804263e90dac943e9") } > db.demo673.insertOne({Name:"David",Age:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3ec7f04263e90dac943ea") }
Display all documents from a collection with the help of find() method −
> db.demo673.find();
This will produce the following output −
{ "_id" : ObjectId("5ea3ec7304263e90dac943e8"), "Name" : "John", "Age" : 23 } { "_id" : ObjectId("5ea3ec7804263e90dac943e9"), "Name" : "Bob", "Age" : 21 } { "_id" : ObjectId("5ea3ec7f04263e90dac943ea"), "Name" : "David", "Age" : 20 }
Advertisements