
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
Found 1661 Articles for Big Data Analytics

788 Views
Do not use $ symbol or period (.) because these characters are not allowed for MongoDB field names. The field shouldn’t start with $.Here is an example of the allowed characters −> db.charactersAllowedDemo.insertOne({"Employee Name" : "John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7fefbc8d10a061296a3c6d") }Display all documents from a collection with the help of find() method. The query is as follows −> db.charactersAllowedDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c7fefbc8d10a061296a3c6d"), "Employee Name" : "John" }

395 Views
There is no difference between count() and find().count(). Let us see how both of them works. 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.countDemo.insertOne({"UserId":1, "UserName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f9d278d10a061296a3c5d") } > db.countDemo.insertOne({"UserId":2, "UserName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f9d308d10a061296a3c5e") } > db.countDemo.insertOne({"UserId":3, "UserName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f9d3a8d10a061296a3c5f") } > db.countDemo.insertOne({"UserId":4, "UserName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f9d428d10a061296a3c60") }Display all documents from a collection with the help ... Read More

895 Views
Use $in operator to query an array of arrays 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.arrayOfArraysDemo.insertOne({"EmployeeName":"Larry", "EmployeeSkills":[["Java", "MongoDB", "MySQL", "SQL Server"]]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f7a8d8d10a061296a3c5b") } > db.arrayOfArraysDemo.insertOne({"EmployeeName":"Mike", "EmployeeSkills":[["C", "C++"]]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f7aa68d10a061296a3c5c") }Display all documents from a collection with the help of find() method. The query is as follows −> db.arrayOfArraysDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c7f7a8d8d10a061296a3c5b"), "EmployeeName" : "Larry", "EmployeeSkills" : ... Read More

244 Views
Use $nin operator along with $elemMatch and $not for this. 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.combinationOfArrayDemo.insertOne({"StudentName":"Larry", "StudentAge":21, "StudentFavouriteTechnicalSubject":["C", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f77cc8d10a061296a3c58") } > db.combinationOfArrayDemo.insertOne({"StudentName":"Mike", "StudentAge":23, "StudentFavouriteTechnicalSubject":["C++", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f77dc8d10a061296a3c59") } > db.combinationOfArrayDemo.insertOne({"StudentName":"David", "StudentAge":22, "StudentFavouriteTechnicalSubject":["Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f77f48d10a061296a3c5a") }Display all documents from a collection with the help of find() method. The query is as follows −> db.combinationOfArrayDemo.find().pretty();The following is the output ... Read More

389 Views
You can perform distinct with multiple keys with the help of an aggregate framework.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.distinctWithMultipleKeysDemo.insertOne({"StudentName":"Mike", "StudentAge":22, "StudentMathMarks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f74488d10a061296a3c53") } > db.distinctWithMultipleKeysDemo.insertOne({"StudentName":"Mike", "StudentAge":22, "StudentMathMarks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f744b8d10a061296a3c54") } > db.distinctWithMultipleKeysDemo.insertOne({"StudentName":"Bob", "StudentAge":23, "StudentMathMarks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f74598d10a061296a3c55") } > db.distinctWithMultipleKeysDemo.insertOne({"StudentName":"Bob", "StudentAge":23, "StudentMathMarks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f745e8d10a061296a3c56") } > db.distinctWithMultipleKeysDemo.insertOne({"StudentName":"Carol", "StudentAge":27, "StudentMathMarks":54}); { "acknowledged" ... Read More

254 Views
Use regexp to make case-insensitive queries on 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.caseInsensitiveDemo.insertOne({"UserName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f6fec8d10a061296a3c45") } > db.caseInsensitiveDemo.insertOne({"UserName":"DAVID"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f6ff28d10a061296a3c46") } > db.caseInsensitiveDemo.insertOne({"UserName":"david"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f6ffa8d10a061296a3c47") } > db.caseInsensitiveDemo.insertOne({"UserName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f70008d10a061296a3c48") } > db.caseInsensitiveDemo.insertOne({"UserName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f70058d10a061296a3c49") } > db.caseInsensitiveDemo.insertOne({"UserName":"Sam"}); { "acknowledged" : true, "insertedId" : ... Read More

2K+ Views
To remove an element from a doubly-nested array in MongoDB document, you can use $pull operator.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.removeElementFromDoublyNestedArrayDemo.insertOne( ... { ... "_id" : "1", ... "UserName" : "Larry", ... "UserDetails" : [ ... { ... "UserCountryName" : "US", ... "UserLocation" : [ ... { ... Read More

436 Views
You can achieve this with the help of $addFields operator. 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.addFieldDemo.insertOne({"EmployeeId":101, "EmployeeName":"Larry", "EmployeeDetails":{ "EmployeeSalary":65000, "EmployeeCity":"New York", "Message":"Hi"}}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f654d8d10a061296a3c44") }Display all documents from a collection with the help of find() method. The query is as follows −> db.addFieldDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c7f654d8d10a061296a3c44"), "EmployeeId" : 101, "EmployeeName" : "Larry", "EmployeeDetails" : { "EmployeeSalary" : 65000, ... Read More

947 Views
To auto increment in MongoDB to store a sequence of unique user id, let us create a collection which contains information about last sequence values of all documents.Let us first create a collection. The query to create a collection which is as follows −> db.createSequenceDemo.insertOne({_id:"SID", S_Value:0}); { "acknowledged" : true, "insertedId" : "SID" }Now, we will create a function that will generate an auto increment in MongoDB to store sequence. The query is as follows −> function nextSequence(s) { ... var sd = db.createSequenceDemo.findAndModify({ ... query:{_id: s }, ... update: {$inc:{S_Value:1}}, ... Read More

398 Views
Use the aggregate framework to find all duplicate documents in a MongoDB collection by a key field.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.findDuplicateByKeyDemo.insertOne({"StudentId":1, "StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f5b168d10a061296a3c3a") } > db.findDuplicateByKeyDemo.insertOne({"StudentId":2, "StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f5b1f8d10a061296a3c3b") } > db.findDuplicateByKeyDemo.insertOne({"StudentId":3, "StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f5b248d10a061296a3c3c") } > db.findDuplicateByKeyDemo.insertOne({"StudentId":4, "StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f5b2d8d10a061296a3c3d") } > db.findDuplicateByKeyDemo.insertOne({"StudentId":5, "StudentName":"Sam"}); { "acknowledged" : true, ... Read More