
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
147 Views
Let us see an example and create a collection with documents −> db.demo694.insertOne( ... { ... "details" : ... [ ... { ... "Name" : "Chris", ... ... Read More

AmitDiwan
128 Views
For this, use $slice and set thecount of values to be ignored and displayed. Let us create a collection with documents −> db.demo693.insertOne({Values:[10, 746, 736, 283, 7363, 424, 3535]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea58a04ece4e5779399c07b") } > db.demo693.insertOne({Values:[100, 200, 300, 100, 500, 700, 900, 30000, 40003, 45999]}); ... Read More

AmitDiwan
978 Views
To find documents with specific FirstName and LastName, use $and along with $in. Implement this in MongoDB find(). Let us create a collection with documents −> db.demo692.insertOne({FirstName:"Chris", "LastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea585dca7e81adc6a0b396a") } > db.demo692.insertOne({FirstName:"John", "LastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea585e2a7e81adc6a0b396b") ... Read More

AmitDiwan
163 Views
To rename a collection in MongoDB, use renameCollection(). Let us create a collection with documents −> db.demo690.insertOne({_id:101, Name:"Sam"}); { "acknowledged" : true, "insertedId" : 101 } > db.demo690.insertOne({_id:102, Name:"Mike"}); { "acknowledged" : true, "insertedId" : 102 } > db.demo690.insertOne({_id:103, Name:"John"}); { "acknowledged" : true, "insertedId" : 103 }Display all documents ... Read More

AmitDiwan
235 Views
For multiple insert, use insert() in MongoDB. Let us create a collection with document −> db.demo689.insert([ ... {ClientName:"Chris", "ClientAge":34, "ClientCountryName":"US"}, ... {ClientName:"David", "ClientAge":28, "ClientCountryName":"UK"}, ... {ClientName:"Bob", "ClientAge":39, "ClientCountryName":"AUS"}, ... ]); BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 3, "nUpserted" ... Read More

AmitDiwan
326 Views
Let’s say we need to find a document with a value greater than specific value. For this, use dot notation in nested document and set the condition with $gt.Let us see an example and create a collection with documents −> db.demo688.insert( ... { ... information:{id:1, details:[ ... {otherDetails:{ ... ... Read More

AmitDiwan
656 Views
For this, use aggregate(). Let’s say we have to fetch documents with a field “Age” with value “21”.Let us now create a collection with documents −> db.demo685.insertOne( ... { ... "details": ... [ ... { ... ... Read More

AmitDiwan
668 Views
To access inner element of JSON array in MongoDB, use dot notation. Let us create a collection with documents −> db.demo687.insert({CountryName:'US', ... info: ... { ... id:101, ... details: ... [ ... { ... Name:'Chris', ... SubjectName:'MongoDB', ... otherDetails:{ ... "Marks":58, ... ... Read More

AmitDiwan
367 Views
To implement similar to “like”, use find() along with // in MongoDB. Let us create a collection with documents −> db.demo686.insertOne({"FirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea55182a7e81adc6a0b395c") } > db.demo686.insertOne({"FirstName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea55186a7e81adc6a0b395d") } > db.demo686.insertOne({"FirstName":"ROBERT"}); { "acknowledged" : true, ... Read More

AmitDiwan
841 Views
Use $natural to sort natural in MongoDB. Let us create a collection with documents −> db.demo684.insertOne({Value:10}); { "acknowledged" : true, "insertedId" : ObjectId("5ea530cea7e81adc6a0b3957") } > db.demo684.insertOne({Value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5ea530d1a7e81adc6a0b3958") } > db.demo684.insertOne({Value:60}); { "acknowledged" : true, "insertedId" : ObjectId("5ea530d4a7e81adc6a0b3959") } ... Read More