- Trending Categories
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
Found 1659 Articles for Big Data Analytics
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
544 Views
The collMod makes it possible to add options to a collection or to modify view definitions. You can use runCommand() along with collMod(). Let us first create a collection with documents −> db.demo13.insertOne({"StudentFirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f730ad7df943a7cec4fa6") } > db.demo13.insertOne({"StudentFirstName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f7310d7df943a7cec4fa7") } > db.demo13.insertOne({"StudentFirstName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f7313d7df943a7cec4fa8") }Following is the query to display all documents from a collection with the help of find() method −> db.demo13.find();This will produce the following output −{ "_id" : ObjectId("5e0f730ad7df943a7cec4fa6"), "StudentFirstName" : "Chris" } { "_id" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
162 Views
For nested search, use $and along with $or. Let us first create a collection with documents −> db.demo12.insertOne({"Name":"Chris", "Age":23, "CountryName":"US", "Message":"Hello"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f70a2d7df943a7cec4fa2") } > db.demo12.insertOne({"Name":"David", "Age":21, "CountryName":"US", "Message":"Hello"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f70acd7df943a7cec4fa3") } > db.demo12.insertOne({"Name":"Bob", "Age":23, "CountryName":"AUS", "Message":"Hi"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f70bad7df943a7cec4fa4") } > db.demo12.insertOne({"Name":"Carol", "Age":24, "CountryName":"US", "Message":"Hi"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f70c7d7df943a7cec4fa5") }Following is the query to display all documents from a collection with the help of find() method −> db.demo12.find();This will produce the following output −{ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
565 Views
Let us first create a collection with documents −>db.demo11.insertOne({"ListOfStudent":[{"StudentName":"Chris", "ListOfScore":[76, 67, 54, 89]}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f6e34d7df943a7cec4fa1") }Following is the query to display all documents from a collection with the help of find() method −> db.demo11.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e0f6e34d7df943a7cec4fa1"), "ListOfStudent" : [ { "StudentName" : "Chris", "ListOfScore" : [ 76, 67, 54, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
638 Views
For a single field, use find(). Let us first create a collection with documents −> db.demo10.insertOne({"StudentId":101, "StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f68a7d7df943a7cec4f9b") } > db.demo10.insertOne({"StudentId":102, "StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f68afd7df943a7cec4f9c") } > db.demo10.insertOne({"StudentId":103, "StudentName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f68b5d7df943a7cec4f9d") }Following is the query to display all documents from a collection with the help of find() method −> db.demo10.find();This will produce the following output −{ "_id" : ObjectId("5e0f68a7d7df943a7cec4f9b"), "StudentId" : 101, "StudentName" : "Chris" } { "_id" : ObjectId("5e0f68afd7df943a7cec4f9c"), "StudentId" : 102, "StudentName" : "David" } { "_id" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
504 Views
For this, use update command and $push. Let us first create a collection with documents −>db.demo9.insertOne({"StudentDetails":[{"StudentName":"Chris", "ListOfSubject":["MySQL", "Java"]}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e0f6438d7df943a7cec4f94") }Following is the query to display all documents from a collection with the help of find() method −> db.demo9.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e0f6438d7df943a7cec4f94"), "StudentDetails" : [ { "StudentName" : "Chris", "ListOfSubject" : [ "MySQL", "Java" ] ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
245 Views
To compare two fields, use $where in MongoDB. Let us first create a collection with documents −> db.demo7.insertOne({"FirstName1":"JOHN", "FirstName2":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0ccd1a25ddae1f53b6222f") } > db.demo7.insertOne({"FirstName1":"Carol", "FirstName2":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0ccd2725ddae1f53b62230") } > db.demo7.insertOne({"FirstName1":"bob", "FirstName2":"BOB"}); { "acknowledged" : true, "insertedId" : ObjectId("5e0ccd3225ddae1f53b62231") }Following is the query to display all documents from a collection with the help of find() method −> db.demo7.find();This will produce the following output −{ "_id" : ObjectId("5e0ccd1a25ddae1f53b6222f"), "FirstName1" : "JOHN", "FirstName2" : "John" } { "_id" : ObjectId("5e0ccd2725ddae1f53b62230"), "FirstName1" : "Carol", "FirstName2" : "Mike" } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
120 Views
For this, you can use aggregate(). Let us first create a collection with documents with a vlaue as -infinity −> db.demo5.insertOne({ "_id" : 100, "seq" : 10, "Value" : -Infinity }); { "acknowledged" : true, "insertedId" : 100 } > db.demo5.insertOne({ "_id" : 101, "seq" : 10, "Value" : 50 }); { "acknowledged" : true, "insertedId" : 101 } > db.demo5.insertOne({ "_id" : 102, "seq" : 20, "Value" : 60 }); { "acknowledged" : true, "insertedId" : 102 } > db.demo5.insertOne({ "_id" : 103, "seq" : 20, "Value" : 50 }); { "acknowledged" : true, "insertedId" : 103 }Following is ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
660 Views
Yes, MongoDB can easily index a null value. Let us first create a collection with documents −> db.demo170.createIndex({"Value":1}, {unique:true}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo170.insert({"Value":100}); WriteResult({ "nInserted" : 1 }) > db.demo170.insert({"Value":null}); WriteResult({ "nInserted" : 1 }) > db.demo170.insert({"Value":90}); WriteResult({ "nInserted" : 1 }) > db.demo170.insert({"Value":78}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo170.find();This will produce the following output −{ "_id" : ObjectId("5e369b789e4f06af551997da"), "Value" : 100 } { "_id" : ObjectId("5e369b7c9e4f06af551997db"), "Value" : null } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To fetch all the ids, simply use find() in MongoDB. Let us create a collection with documents −> db.demo169.insertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e36975e9e4f06af551997d7") } > db.demo169.insertOne({"StudentName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3697629e4f06af551997d8") } > db.demo169.insertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3697679e4f06af551997d9") }Display all documents from a collection with the help of find() method −> db.demo169.find();This will produce the following output −{ "_id" : ObjectId("5e36975e9e4f06af551997d7"), "StudentName" : "Chris" } { "_id" : ObjectId("5e3697629e4f06af551997d8"), "StudentName" : "Bob" } { "_id" : ObjectId("5e3697679e4f06af551997d9"), "StudentName" : "David" }Following is the query to get ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
97 Views
To increment a date, use setDate, getDate() and perform increment operation. Let us first create a collection with documents −> db.demo168.insertOne({"DueDate":null}); { "acknowledged" : true, "insertedId" : ObjectId("5e3695ae9e4f06af551997d6") }Display all documents from a collection with the help of find() method −> db.demo168.find();This will produce the following output −{ "_id" : ObjectId("5e3695ae9e4f06af551997d6"), "DueDate" : null }Following is the query to increment a date in JavaScript, in order to update MongoDB −> var t = new Date(); > t.setDate(t.getDate()+1); 1580722089017 > > var dat = new Date(); > dat .setDate(dat .getDate()+2); 1580808489085 > > db.demo168.update( ... { "_id": ObjectId("5e3695ae9e4f06af551997d6") ... Read More