- 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
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
617 Views
To find the largest document size in MongoDB, you need to write a script in the shell.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.largestDocumentDemo.insertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed2e32f684a30fbdfd57d") } > db.largestDocumentDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentCountryName":"US", "TechnicalSubject":["C", "C++", "Java", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3282f684a30fbdfd57e") } > db.largestDocumentDemo.insertOne({"StudentName":"Mike", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3382f684a30fbdfd57f") }Display all documents from a collection with the help of find() method. The query is as follows −> ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
2K+ Views
You can use $in operator to find through the list of ids in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.findListOfIdsDemo.insertOne({"StudentName":"Carol", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ecadd2f684a30fbdfd575") } > db.findListOfIdsDemo.insertOne({"StudentName":"Bob", "StudentAge":25}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ecae42f684a30fbdfd576") } > db.findListOfIdsDemo.insertOne({"StudentName":"David", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ecaed2f684a30fbdfd577") } > db.findListOfIdsDemo.insertOne({"StudentName":"John", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ecaf82f684a30fbdfd578") } > db.findListOfIdsDemo.insertOne({"StudentName":"Mike", "StudentAge":23}); { "acknowledged" : true, "insertedId" ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
390 Views
To understand the query with an or condition, let us create a collection with the document. The query to create a collection with a document is as follows −> db.orConditionDemo.insertOne({"CustomerName":"Larry", "ShippingDate":new ISODate("2018-01-29")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ec5262f684a30fbdfd56a") } > db.orConditionDemo.insertOne({"CustomerName":"Mike", "ShippingDate":new ISODate("2019-04-13")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ec5362f684a30fbdfd56b") } > db.orConditionDemo.insertOne({"CustomerName":"Bob", "ShippingDate":new ISODate("2019-02-21")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ec5422f684a30fbdfd56c") } > db.orConditionDemo.insertOne({"CustomerName":"David", "ShippingDate":new ISODate("2019-03-15")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ec5532f684a30fbdfd56d") } > db.orConditionDemo.insertOne({"CustomerName":"John", "ShippingDate":new ISODate("2019-03-19")}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ec56c2f684a30fbdfd56e") }Display all documents ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
479 Views
You can return a specific field from collection.find() by using the following syntax.Case 1 − The syntax is as follows −db.yourCollectionName.find({}, {"yourFieldName":1}).pretty();The above field name is set to 1 means it will return only that field. If you set to 0 it will return all fields except the field which is set to 0.Case 2 − The syntax is as follows −db.yourCollectionName.find({}, {"yourFieldName":0}).pretty();To understand the above syntaxes, let us create a collection with document. The query to create a collection with document is as follows −> db.returnFieldInFindDemo.insertOne({"StudentName":"John", "StudentAge":23, "TechnicalSubject":["MongoDB", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ebfe72f684a30fbdfd566") } ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
1K+ Views
You can use ensureIndex() to boost the performance of count() method in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.countPerformanceDemo.insertOne({"StudentName":"John", "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ebcf82f684a30fbdfd55f") } > db.countPerformanceDemo.insertOne({"StudentName":"Mike", "StudentCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ebd042f684a30fbdfd560") } > db.countPerformanceDemo.insertOne({"StudentName":"David", "StudentCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ebd112f684a30fbdfd561") } > db.countPerformanceDemo.insertOne({"StudentName":"Carol", "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ebd1a2f684a30fbdfd562") } > db.countPerformanceDemo.insertOne({"StudentName":"Bob", "StudentCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
647 Views
You can use $set operator for this. The syntax is as follows −db.yourCollectionName.update({ }, {'$set': "yourFieldName": "yourValue" }, false, true);To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.unconditionalUpdatesDemo.insertOne({"ClientName":"Larry", "ClientAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7372f684a30fbdfd557") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Mike", "ClientAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb73f2f684a30fbdfd558") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Sam", "ClientAge":27}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7462f684a30fbdfd559") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Carol", "ClientAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5c8eb7502f684a30fbdfd55a") }Display all documents from a ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
2K+ Views
You can restrict case insensitive search in MongoDB with the help of '$regex'. The syntax is as follows −db.yourCollectionName.find({"yourFieldName" : { '$regex':'^yourValue$'}});You can use another regex. The syntax is as follows −db.yourCollectionName.find({"Name" : { '$regex':/^yourValue$/i}});To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.caseInsesitiveDemo.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bd66293c80e3f23815e83") } > db.caseInsesitiveDemo.insertOne({"Name":"Johnson"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bd66693c80e3f23815e84") } > db.caseInsesitiveDemo.insertOne({"Name":"Johny"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bd66a93c80e3f23815e85") }Display all documents from a collection with ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
84 Views
To write on console, you need to use print() method. The syntax is as follows −print(“yourString”);To display objects, you can use printjson(). The syntax is as follows −printjson(yourObjectName);Let us implement both the functions. The first query is as follows to display something −> print("Welcome to MongoDB Console");The following is the output on a console −Welcome to MongoDB ConsoleLet us create an object. The query is as follows −>studentInformation={"StudentName":"John", "StudentAge":24, "StudentTechnicalSkills":["C", "C++", "Java", "MongoDB", "MySQL"]}; { "StudentName" : "John", "StudentAge" : 24, "StudentTechnicalSkills" : [ "C", "C++", "Java", ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
579 Views
To clone a collection in MongoDB, you can use the forEach() method. Let us first create a collection with a document.The query to create a collection with a document is as follows −> db.studentInformation.insertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc15780f10143d8431e21") } > db.studentInformation.insertOne({"StudentName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc15e80f10143d8431e22") } > db.studentInformation.insertOne({"StudentName":"James"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bc17380f10143d8431e23") }Display all documents from a collection with the help of find() method. The query is as follows −> db.studentInformation.find().pretty();The following is the output −{ "_id" : ObjectId("5c8bc15780f10143d8431e21"), "StudentName" : "Chris" } { "_id" ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
972 Views
To get the element with a max id, you can use the find() method. To understand the above concept, let us create a collection with the document. The query is as follows −> db.getElementWithMaxIdDemo.insertOne({"Name":"John", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bbce480f10143d8431e1c") } > db.getElementWithMaxIdDemo.insertOne({"Name":"Larry", "Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bbcec80f10143d8431e1d") } > db.getElementWithMaxIdDemo.insertOne({"Name":"David", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bbcf580f10143d8431e1e") } > db.getElementWithMaxIdDemo.insertOne({"Name":"Chris", "Age":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bbcfe80f10143d8431e1f") } > db.getElementWithMaxIdDemo.insertOne({"Name":"Robert", "Age":25}); { "acknowledged" : true, "insertedId" : ObjectId("5c8bbd0880f10143d8431e20") }Display all documents from ... Read More