
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

162 Views
You can use positional operator $ for this. Let us first create a collection with documents −> db.subElementQueryingDemo.insertOne( ... { ... "ClientName":"Chris", ... "Status": [ { "isMarried": true }, { "isMarried": false } ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ccf28c9dceb9a92e6aa1953") }Following is the query to display all documents from a collection with the help of find() method −> db.subElementQueryingDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccf28c9dceb9a92e6aa1953"), "ClientName" : "Chris", "Status" : [ { ... Read More

4K+ Views
Use typeof to find datatype of all the fields −typeof db.yourCollectionName.findOne().yourFieldName;Let us first create a collection with documents −> db.findDataTypeDemo.insertOne({"ClientName":"Chris", "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf2064dceb9a92e6aa1952") }Following is the query to display all documents from a collection with the help of find() method −> db.findDataTypeDemo.findOne();This will produce the following output −{ "_id" : ObjectId("5ccf2064dceb9a92e6aa1952"), "ClientName" : "Chris", "isMarried" : false }Following is the query to find datatype of a field in MongoDB −> typeof db.findDataTypeDemo.findOne().isMarried;This will produce the following output −BooleanHere is the query to get the data type of another field −> ... Read More

566 Views
You need to set numericOrdering: true for alphanumeric sort. Let us first create a collection with documents −> db.alphanumericSortDemo.insertOne({"StudentId":"STU1010"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf149adceb9a92e6aa194c") } > db.alphanumericSortDemo.insertOne({"StudentId":"STU1101"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf14a2dceb9a92e6aa194d") } > db.alphanumericSortDemo.insertOne({"StudentId":"STU1901"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf14a9dceb9a92e6aa194e") } > db.alphanumericSortDemo.insertOne({"StudentId":"STU908"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf14aedceb9a92e6aa194f") } > db.alphanumericSortDemo.insertOne({"StudentId":"STU101"}); { "acknowledged" : true, "insertedId" : ObjectId("5ccf14b2dceb9a92e6aa1950") }Following is the query to display all documents from a collection with the help of find() method −> db.alphanumericSortDemo.find().pretty();This will produce the following output ... Read More

295 Views
To reverse array field in MongoDB, you can use forEach(). Let us first create a collection with documents −> db.reverseArrayDemo.insertOne({"Skills":["C", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5ccddf99dceb9a92e6aa1946") }Following is the query to display all documents from a collection with the help of find() method −> db.reverseArrayDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ccddf99dceb9a92e6aa1946"), "Skills" : [ "C", "Java" ] }Here is the query to reverse array field in MongoDB −> db.reverseArrayDemo.find().forEach(function (myDocument) { ... var arrayValue = [ myDocument.Skills[1], myDocument.Skills[0] ]; ... db.reverseArrayDemo.update(myDocument, { ... Read More

328 Views
You can use $set operator for this. Let us first create a collection with documents −> db.pullAllElementDemo.insertOne( ... { ... "StudentId":101, ... "StudentDetails" : [ ... { ... ... "StudentName": "Carol", ... "StudentAge":21, ... "StudentCountryName":"US" ... }, ... { ... "StudentName": "Chris", ... "StudentAge":24, ... ... Read More

607 Views
To update object at specific array index, use update() in MongoDB. Let us first create a collection with documents −> db.updateObjectDemo.insertOne( ... { ... id : 101, ... "StudentDetails": ... [ ... [ ... { ... "StudentName": "John" ... }, ... { "StudentName": "Chris" } ... ], ... [ { "StudentName": "Carol" }, ... Read More

375 Views
To increment a field in MongoDB, you can use $inc operator. Let us first create a collection with documents −> db.incrementDemo.insertOne({"PlayerScore":100}); { "acknowledged" : true, "insertedId" : ObjectId("5cc81cdd8f9e6ff3eb0ce44e") } > db.incrementDemo.insertOne({"PlayerScore":290}); { "acknowledged" : true, "insertedId" : ObjectId("5cc81ce28f9e6ff3eb0ce44f") } > db.incrementDemo.insertOne({"PlayerScore":560}); { "acknowledged" : true, "insertedId" : ObjectId("5cc81ce68f9e6ff3eb0ce450") }Following is the query to display all documents from a collection with the help of find() method −> db.incrementDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc81cdd8f9e6ff3eb0ce44e"), "PlayerScore" : 100 } { "_id" : ObjectId("5cc81ce28f9e6ff3eb0ce44f"), "PlayerScore" : 290 } { "_id" : ObjectId("5cc81ce68f9e6ff3eb0ce450"), "PlayerScore" : ... Read More

6K+ Views
You can use $eq as well as $ne operator for boolean values. Let us first create a collection with documents −> db.booleanQueryDemo.insertOne({"UserName":"John", "UserAge":23, "isMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cc815c08f9e6ff3eb0ce44a") } > db.booleanQueryDemo.insertOne({"UserName":"Chris", "UserAge":21, "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cc815d08f9e6ff3eb0ce44b") } > db.booleanQueryDemo.insertOne({"UserName":"Robert", "UserAge":24, "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cc815dc8f9e6ff3eb0ce44c") } > db.booleanQueryDemo.insertOne({"UserName":"David", "UserAge":26, "isMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cc815ed8f9e6ff3eb0ce44d") }Following is the query to display all documents from a collection with the help of find() method −> db.booleanQueryDemo.find().pretty();This will produce the following output −{ ... Read More

323 Views
You can concatenate results with the help of forEach(). Let us first create a collection with documents −> db.concatenateDemo.insertOne({"Name":"John", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cc80dd88f9e6ff3eb0ce448") } > db.concatenateDemo.insertOne({"Name":"Carol", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cc80de18f9e6ff3eb0ce449") }Following is the query to display all documents from a collection with the help of find() method −> db.concatenateDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc80dd88f9e6ff3eb0ce448"), "Name" : "John", "Age" : 21 } { "_id" : ObjectId("5cc80de18f9e6ff3eb0ce449"), "Name" : "Carol", "Age" : 23 }Here is the query to concatenate results ... Read More

147 Views
You can use only $pull operator that removes and updates the existing record in MongoDB. Let us first create a collection with documents −> db.removeDemo.insertOne( ... { ... "UserName" : "Larry", ... "UserDetails" : [ ... { ... "_id" : 101, ... "UserEmailId" : "976Larry@gmail.com", ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cc7f9f88f9e6ff3eb0ce446") } > db.removeDemo.insertOne( ... { ... ... Read More