Data Structure
 Networking
 RDBMS
 Operating System
 Java
 MS Excel
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP
- Selected Reading
 - UPSC IAS Exams Notes
 - Developer's Best Practices
 - Questions and Answers
 - Effective Resume Writing
 - HR Interview Questions
 - Computer Glossary
 - Who is Who
 
AmitDiwan has Published 10744 Articles
 
							AmitDiwan
470 Views
To limit the number of documents in a collection, set capped − true. Set the size there itself. Let us create a collection with documents −> db.createCollection( "demo683", { capped: true, size: 5 ,max:4} ) { "ok" : 1 } > db.demo683.insertOne({Value:100}); { "acknowledged" : true, "insertedId" : ... Read More
 
							AmitDiwan
175 Views
Yes, you can skip some documents using skip() in MongoDB. Use limit() to display how many documents you want to display after skipping some. Let us create a collection with documents −> db.demo682.insertOne({FirstName:"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462a804263e90dac94402") } > db.demo682.insertOne({FirstName:"Sam"}); { "acknowledged" : true, ... Read More
 
							AmitDiwan
205 Views
To get the topmost document, use find() along with limit(). To fetch only a single document, consider using limit(1). Let us create a collection with documents −> db.demo681.insertOne({_id:101, Name:"Chris"}); { "acknowledged" : true, "insertedId" : 101 } > db.demo681.insertOne({_id:102, Name:"Bob"}); { "acknowledged" : true, "insertedId" : 102 } > db.demo681.insertOne({_id:103, ... Read More
 
							AmitDiwan
231 Views
The $and performs a logical AND operation on an array of one or more expressions. Let us create a collection with documents −> db.demo680.insertOne({Values:40}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461b04263e90dac943fe") } > db.demo680.insertOne({Values:70}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461e04263e90dac943ff") } > db.demo680.insertOne({Values:[80, 30]}); { ... Read More
 
							AmitDiwan
282 Views
Let us create a collection with documents −> db.demo677.insertOne({Value:10}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421f404263e90dac943f8") } > db.demo677.insertOne({Value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421f704263e90dac943f9") } > db.demo677.insertOne({Value:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea421fa04263e90dac943fa") } > db.demo677.insertOne({Value:20}); { "acknowledged" : true, ... Read More
 
							AmitDiwan
207 Views
For group query, use MongoDB $group and get the count with $sum. Let us create a collection with documents −> db.demo676.insertOne({"Marks":87}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41eed04263e90dac943f2") } > db.demo676.insertOne({"Marks":75}); { "acknowledged" : true, "insertedId" : ObjectId("5ea41ef304263e90dac943f3") } > db.demo676.insertOne({"Marks":87}); { "acknowledged" : true, ... Read More
 
							AmitDiwan
157 Views
Let us create a collection with documents −> db.demo675.insertOne({ ... "ListOfNames":["John", "Chris", "David"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f5b404263e90dac943ef") } > db.demo675.insertOne({ "ListOfNames":["Bob", "Johnson", "Sam"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f5c804263e90dac943f0") } > db.demo675.insertOne({ "ListOfNames":["Jace", "Sam"]}); { "acknowledged" : true, "insertedId" : ... Read More
 
							AmitDiwan
198 Views
The $or operator performs a logical OR operation on an array of two or more expressions. Let us create a collection with documents −> db.demo674.insertOne({Name:"Chris", Age:21}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f33604263e90dac943eb") } > db.demo674.insertOne({Name:"David", Age:23}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3f33c04263e90dac943ec") } > ... Read More
 
							AmitDiwan
102 Views
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 ... Read More
 
							AmitDiwan
232 Views
To fetch a specific document, use dot notation in MongoDB find(). Let us create a collection with documents −> db.demo672.insertOne({Brand:[{CategoryName:"Mobile", "Name":"Oppo"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3ea9b04263e90dac943e5") } > db.demo672.insertOne({Brand:[{CategoryName:"Mobile", "Name":"Samsung"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3eaa404263e90dac943e6") } > db.demo672.insertOne({Brand:[{CategoryName:"Mobile", "Name":"OnePlus"}]}); { "acknowledged" ... Read More