- 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 1669 Articles for Big Data Analytics
286 Views
To sort in ascending order, the syntax is as follows −db.yourCollectionName.find().sort({yourField:1});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.sortingDemo.insertOne({"Value":100}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e31d3c9d04998abf007") } > db.sortingDemo.insertOne({"Value":150}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e34d3c9d04998abf008") } > db.sortingDemo.insertOne({"Value":250}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e37d3c9d04998abf009") } > db.sortingDemo.insertOne({"Value":5}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e3bd3c9d04998abf00a") } > db.sortingDemo.insertOne({"Value":199}); { "acknowledged" : ... Read More
172 Views
To sort in ascending order, the syntax is as follows −db.yourCollectionName.find().sort({yourField:1});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.sortingDemo.insertOne({"Value":100}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e31d3c9d04998abf007") } > db.sortingDemo.insertOne({"Value":150}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e34d3c9d04998abf008") } > db.sortingDemo.insertOne({"Value":250}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e37d3c9d04998abf009") } > db.sortingDemo.insertOne({"Value":5}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e3bd3c9d04998abf00a") } > db.sortingDemo.insertOne({"Value":199}); { "acknowledged" : ... Read More
358 Views
You can use distinct() method in MongoDB to get distinct record values. The syntax is as follows −db.yourCollectionName.distinct(“yourFieldName”);To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows −> db.distinctRecordDemo.insertOne({"StudentId":1, "StudentName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a78299b97a65744c1b50") } > db.distinctRecordDemo.insertOne({"StudentId":2, "StudentName":"John", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a78b99b97a65744c1b51") } > db.distinctRecordDemo.insertOne({"StudentId":3, "StudentName":"Carol", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a79a99b97a65744c1b52") } > db.distinctRecordDemo.insertOne({"StudentId":4, "StudentName":"Carol", "StudentAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a7a499b97a65744c1b53") } > db.distinctRecordDemo.insertOne({"StudentId":5, "StudentName":"Sam", "StudentAge":24}); ... Read More
190 Views
You can achieve this 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.countGroupByDemo.insertOne({"StudentId":10, "StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700871e9c5dd6f1f78296") } > db.countGroupByDemo.insertOne({"StudentId":10, "StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77008f1e9c5dd6f1f78297") } > db.countGroupByDemo.insertOne({"StudentId":20, "StudentName":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700971e9c5dd6f1f78298") } > db.countGroupByDemo.insertOne({"StudentId":30, "StudentName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700a21e9c5dd6f1f78299") } > db.countGroupByDemo.insertOne({"StudentId":30, "StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700aa1e9c5dd6f1f7829a") } ... Read More
2K+ Views
You can use $ne(Not Equal) operator for this. To understand the concept, let us create a collection with document. The query to create a collection with document is as follows −> db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Larry", "StudentTechnicalSubject":["Java", "C"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe2f1e9c5dd6f1f78291") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Mike", "StudentTechnicalSubject":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe3b1e9c5dd6f1f78292") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Sam", "StudentTechnicalSubject":["MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe491e9c5dd6f1f78293") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Carol", "StudentTechnicalSubject":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe521e9c5dd6f1f78294") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"David", "StudentTechnicalSubject":["MySQL", "SQL Server"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe661e9c5dd6f1f78295") }Display all documents ... Read More
168 Views
You can use the $exists and $ne operator for this. To understand the concept further, let us create a collection with document. The query to create a collection with document is as follows −> db.checkFieldExistDemo.insertOne({"EmployeeId":1, "EmployeeName":"John", "isMarried":true, "EmployeeSalary":4648585}); { "acknowledged" : true, "insertedId" : ObjectId("5c76f7b31e9c5dd6f1f78281") } > db.checkFieldExistDemo.insertOne({"StudentId":2, "StudentName":"John", "isMarried":false, " StudentAge":19}); { "acknowledged" : true, 0 "insertedId" : ObjectId("5c76f7e11e9c5dd6f1f78282") }Display all documents from a collection with the help of find() method. The query is as follows −> db.checkFieldExistDemo.find().pretty();Output{ "_id" : ObjectId("5c76f7b31e9c5dd6f1f78281"), "EmployeeId" : 1, "EmployeeName" : "John", "isMarried" : true, ... Read More
311 Views
You can get documents with max attribute per group in a collection using $sort operator along with $group statement.To understand the concept further, let us create a collection with document. The query to create a collection with document is as follows −> db.maxAttributePerGroup.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith ", "StudentAge":29, "StudentId":10}); { "acknowledged" : true, "insertedId" : ObjectId("5c76ee341e9c5dd6f1f78277") } > db.maxAttributePerGroup.insertOne({"StudentFirstName":"Carol", "StudentLastName":"Taylo r", "StudentAge":19, "StudentId":10}); { "acknowledged" : true, "insertedId" : ObjectId("5c76ee4e1e9c5dd6f1f78278") } > db.maxAttributePerGroup.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smit h", "StudentAge":34, "StudentId":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c76ee631e9c5dd6f1f78279") } > db.maxAttributePerGroup.insertOne({"StudentFirstName":"Bob", "StudentLastName":"Taylor" , "StudentAge":58, "StudentId":20}); { ... Read More
816 Views
In order to replace substring in MongoDB document, you can use the replace() function. To understand it further, let us create a collection with document. The query to create a collection with document is as follows −> db.replaceSubstringDemo.insertOne({"WebsiteURL":"www.gogle.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5c76eaf21e9c5dd6f1f78276") }Display all documents from a collection with the help of find() method. The query is as follows −> db.replaceSubstringDemo.find().pretty();Output{ "_id" : ObjectId("5c76eaf21e9c5dd6f1f78276"), "WebsiteURL" : "www.gogle.com" }Here is the query to replace substring in MongoDB document −> db.replaceSubstringDemo.find({WebsiteURL:"www.gogle.com"}).forEach(function(url, k){ ... url.WebsiteURL=url.WebsiteURL.replace("www.gogle.com", "www.google.com"); ... db.replaceSubstringDemo.save(url) ... });Let us display the ... Read More
608 Views
You can use $facet operator for this. To understand the concept, let us create a collection with document. The query to create a collection with document is as follows −> db.totalDocumentDemo.insertOne({"InstructorId":100, "InstructorName":"Larry", "InstructorFav ouriteSubject":["Java", "MongoDB", "Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e6701e9c5dd6f1f78274") } > db.totalDocumentDemo.insertOne({"InstructorId":200, "InstructorName":"Sam", "InstructorFav ouriteSubject":["SQL Server", "C#", "Javascript"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e69c1e9c5dd6f1f78275") }Display all documents from a collection with the help of find() method. The query is as follows −> db.totalDocumentDemo.find().pretty();Output{ "_id" : ObjectId("5c76e6701e9c5dd6f1f78274"), "InstructorId" : 100, "InstructorName" : "Larry", "InstructorFavouriteSubject" : [ ... Read More
1K+ Views
To perform Regex search on integer value, you need to use $where operator. The syntax is as follows:db.yourCollectionName.find({ $where: "/^yourIntegerPatternValue.*/.test(this.yourFieldName)" });To understand the above concept, let us create a collection with document. The query to create a collection with document is as follows:> db.regExpOnIntegerDemo.insertOne({"StudentId":2341234}); { "acknowledged" : true, "insertedId" : ObjectId("5c70370c75eb1743ddddce21") } > db.regExpOnIntegerDemo.insertOne({"StudentId":123234}); { "acknowledged" : true, "insertedId" : ObjectId("5c70371175eb1743ddddce22") } > db.regExpOnIntegerDemo.insertOne({"StudentId":9871234}); { "acknowledged" : true, "insertedId" : ObjectId("5c70371875eb1743ddddce23") } > db.regExpOnIntegerDemo.insertOne({"StudentId":2345612}); { "acknowledged" : true, "insertedId" : ObjectId("5c70372275eb1743ddddce24") } > db.regExpOnIntegerDemo.insertOne({"StudentId":1239812345}); { "acknowledged" : true, "insertedId" : ... Read More
To Continue Learning Please Login
Login with Google