
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

844 Views
You can work with aggregate framework and use $sort, $skip and $limit to display distinctly ordered records with skip and also set the limit. Let us first create a collection with documents> db.orderedDistinctDemo.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb8e0140b992277dae0e9") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb8e5140b992277dae0ea") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb8e7140b992277dae0eb") } > db.orderedDistinctDemo.insertOne({"Name":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb8ea140b992277dae0ec") } > db.orderedDistinctDemo.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb8ee140b992277dae0ed") } > db.orderedDistinctDemo.insertOne({"Name":"Carol"}); { "acknowledged" : true, "insertedId" ... Read More

511 Views
Use drop() to delete a table. Following is the syntax −db.yourCollectionName.drop();Let us first create a collection with documents −> db.deleteTableDemo.insertOne({"Name":"Chris", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb705140b992277dae0e6") } > db.deleteTableDemo.insertOne({"Name":"Carol", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb70c140b992277dae0e7") } > db.deleteTableDemo.insertOne({"Name":"David", "Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb714140b992277dae0e8") }Following is the query to display all documents from a collection with the help of find() method −> db.deleteTableDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccfb705140b992277dae0e6"), "Name" : "Chris", "Age" : 23 } { "_id" : ObjectId("5ccfb70c140b992277dae0e7"), ... Read More

244 Views
For MongoDB collection beginning with_, following is the syntax −db.createCollection(‘_yourCollectionName’);Insert query using below syntax −db.getCollection('_yourCollectionName').insertOne({"yourFieldName1":"yourValue1", "yourFieldName2":yourValue2, ............N});Let us first create a collection with documents −> db.createCollection('_testUnderscoreCollectionDemo'); { "ok" : 1 } >db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"John", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb4a6140b992277dae0e4") } >db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"Carol", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb4af140b992277dae0e5") }Following is the query to display all documents from a collection with the help of find() method −> db.getCollection('_testUnderscoreCollectionDemo').find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccfb4a6140b992277dae0e4"), "StudentFirstName" : "John", "StudentAge" : 23 } { "_id" : ObjectId("5ccfb4af140b992277dae0e5"), ... Read More

1K+ Views
To retrieve a nested object in MongoDB, use $ operator. Let us first create a collection with documents −> db.queryNestedObject.insertOne( ... { ... "StudentName" : "James", ... "StudentSubjectScore" : [ ... {"StudentMongoDBScore":98}, ... {"StudentCScore":92}, ... {"StudentJavaScore":91} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ccf49a9dceb9a92e6aa1962") }Following is the query to display all documents from a collection with the help of find() method −> db.queryNestedObject.find().pretty();This will produce the following output −{ ... Read More

228 Views
Use $addToSet operator to update array element. Let us first create a collection with documents −> db.updateArrayDemo.insertOne( ... { ... ... "ClientDetails" : [ ... { ... "ClientName" : "John", ... "DeveloperDetails" : [ ] ... }, ... { ... "ClientName" : "Larry", ... "DeveloperDetails" : [ ] ... } ... ] ... ... Read More

1K+ Views
The double quotes have unicode which has the value \u0022. Let us first create a collection with documents −> db.escapingQuotesDemo.insert({ "StudentFullName": "John \u0022 Smith" }); WriteResult({ "nInserted" : 1 }) > db.escapingQuotesDemo.insert({ "StudentFullName": "David \u0022 Miller" }); WriteResult({ "nInserted" : 1 }) > db.escapingQuotesDemo.insert({ "StudentFullName": "John \u0022 Doe" }); WriteResult({ "nInserted" : 1 }) > db.escapingQuotesDemo.insert({ "StudentFullName": "Carol \u0022 Taylor" }); WriteResult({ "nInserted" : 1 })Following is the query to display all documents from a collection with the help of find() method −> db.escapingQuotesDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf42e2dceb9a92e6aa195b"), "StudentFullName" : "John \" Smith" ... Read More

249 Views
Let us first create a collection with documents −> db.multipleConditionDemo.insertOne({"_id":1, "Name":"John"}); { "acknowledged" : true, "insertedId" : 1 } > db.multipleConditionDemo.insertOne({"_id":2, "Name":"Carol"}); { "acknowledged" : true, "insertedId" : 2 } > db.multipleConditionDemo.insertOne({"_id":3, "Name":"Sam"}); { "acknowledged" : true, "insertedId" : 3 } > db.multipleConditionDemo.insertOne({"_id":4, "Name":"David"}); { "acknowledged" : true, "insertedId" : 4 }Following is the query to display all documents from a collection with the help of find() method −> db.multipleConditionDemo.find().pretty();This will produce the following output −{ "_id" : 1, "Name" : "John" } { "_id" : 2, "Name" : "Carol" } { "_id" : 3, "Name" : "Sam" } { ... Read More

132 Views
Yes, you can achieve this using aggregate framework. Let us first create a collection with documents −> db.sliceOfSliceDemo.insertOne( ... { ... "Name": "John", ... "Details": [["First 1:1", "First 1:2"], ["second 2:1", "Second 2:2"]] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ccf3fcfdceb9a92e6aa195a") }Following is the query to display all documents from a collection with the help of find() method −> db.sliceOfSliceDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf3fcfdceb9a92e6aa195a"), "Name" : "John", "Details" : [ [ "First ... Read More

204 Views
Prepend string to entire column in MongoDB using aggregate framework. Let us first create a collection with documents −> db.prependDemo.insertOne({"StudentFirstName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf3bcedceb9a92e6aa1955") } > db.prependDemo.insertOne({"StudentFirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf3bd3dceb9a92e6aa1956") } > db.prependDemo.insertOne({"StudentFirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf3bd8dceb9a92e6aa1957") }Following is the query to display all documents from a collection with the help of find() method −> db.prependDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf3bcedceb9a92e6aa1955"), "StudentFirstName" : "John" } { "_id" : ObjectId("5ccf3bd3dceb9a92e6aa1956"), "StudentFirstName" : "Chris" } { "_id" : ObjectId("5ccf3bd8dceb9a92e6aa1957"), ... Read More

175 Views
You can use $setIntersection for this. Let us first create a collection with documents −> db.setInterSectionDemo.insertOne( ... {"_id":101, "Value1":[55, 67, 89]} ... ); { "acknowledged" : true, "insertedId" : 101 } > db.setInterSectionDemo.insertOne( ... {"_id":102, "Value2":[90, 45, 55]} ... ); { "acknowledged" : true, "insertedId" : 102 } > db.setInterSectionDemo.insertOne( ... {"_id":103, "Value3":[92, 67, 45]} ... ); { "acknowledged" : true, "insertedId" : 103 }Following is the query to display all documents from a collection with the help of find() method −> db.setInterSectionDemo.find().pretty();This will produce the following output −{ "_id" : 101, "Value1" : [ 55, 67, ... Read More