
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

161 Views
Yes, we can do that using the NumberLong() datatype in MongoDB. Let us create a collection with documents −> db.demo618.insertOne({_id:NumberLong("6336366454"), Name:"Chris"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366454") } > db.demo618.insertOne({_id:NumberLong("6336366455"), Name:"David"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366455") } > db.demo618.insertOne({_id:NumberLong("6336366456"), Name:"Bob"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366456") }Display all documents from a collection with the help of find() method −> db.demo618.find();This will produce the following output −{ "_id" : NumberLong("6336366454"), "Name" : "Chris" } { "_id" : NumberLong("6336366455"), "Name" : "David" } { "_id" : NumberLong("6336366456"), "Name" : "Bob" }Following is the query to implement MongoDB findOne() ... Read More

297 Views
For this, use dot notation along with $group in MongoDB. Let us create a collection with documents −> db.demo617.insertOne( ... { ... ... "clientDetails": { ... "Name": "Chris", ... "Age":32, ... "Project":"Online Library Management System" ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e99d2b86c954c74be91e69b") } > > db.demo617.insertOne( ... { ... ... "clientDetails": { ... "Name": "David", ... "Age":34, ... ... Read More

660 Views
In MongoDB aggregate(), use $group and aggregate collection. Let us create a collection with documents −> db.demo616.insertOne({"details":{"Name":"Chris", "Age":21}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfac65492f6c60d00283") } > db.demo616.insertOne({"details":{"Name":"Chris", "Age":22}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfb065492f6c60d00284") } > db.demo616.insertOne({"details":{"Name":"Bob", "Age":23}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfb865492f6c60d00285") } > db.demo616.insertOne({"details":{"Name":"Sam", "Age":21}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfbd65492f6c60d00286") } > db.demo616.insertOne({"details":{"Name":"Chris", "Age":24}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfc165492f6c60d00287") }Display all documents from a collection with the help of find() method −> db.demo616.find();This will produce the following output −{ "_id" ... Read More

125 Views
The $type selects documents where the value of the field is an instance of the specified BSON type. Let us create a collection with documents −> db.demo615.insert({"Value":100}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"100"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"300"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":300}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo615.find();This will produce the following output −{ "_id" : ObjectId("5e99bb3465492f6c60d0027f"), "Value" : 100 } { "_id" : ObjectId("5e99bb3865492f6c60d00280"), "Value" : "100" } { "_id" : ObjectId("5e99bb3c65492f6c60d00281"), "Value" : "300" } { "_id" : ObjectId("5e99bb4265492f6c60d00282"), "Value" ... Read More

1K+ Views
The ({$natural − 1}) works like LIFO(LAST IN FIRST OUT), that means last inserted document will be shown first.Let us create a collection with documents −> db.demo614.insertOne({"CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988cddf6b89257f5584d8e") } > db.demo614.insertOne({"CountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988ce0f6b89257f5584d8f") } > db.demo614.insertOne({"CountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988ce3f6b89257f5584d90") } > db.demo614.insertOne({"CountryName":"IND"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988cebf6b89257f5584d91") }Display all documents from a collection with the help of find() method −> db.demo614.find();This will produce the following output −{ "_id" : ObjectId("5e988cddf6b89257f5584d8e"), "CountryName" : "US" } { ... Read More

745 Views
To implement string comparison in MongoDB, use $strcasecmp. It performs case-insensitive comparison of two strings. It returns −1 if first string is “greater than” the second string.0 if the two strings are equal.-1 if the first string is “less than” the second string.Let us create a collection with documents −> db.demo490.insertOne({"Name1":"John", "Name2":"john"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8496ccb0f3fa88e22790bb") } > db.demo490.insertOne({"Name1":"David", "Name2":"Bob"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8496d9b0f3fa88e22790bc") } > db.demo490.insertOne({"Name1":"Carol", "Name2":"Carol"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8496e5b0f3fa88e22790bd") }Display all documents from a collection with the help of find() method −> db.demo490.find();This will produce ... Read More

288 Views
Use update() in MongoDB to update array object. The usage of dot notation is also required. Let us create a collection with documents −> db.demo489.insertOne( ... { ... ... ... details : [{ ... id : 101, ... "Info1" : { ... "StudentName" : "Chris" ... }, ... "Info2" : { ... "TeacherName" : "David" ... } ... }, ... { ... id : 102, ... "Info1" : ... Read More

277 Views
Set the value to be deleted in a variable To delete particle data, use remove(). Let us create a collection with documents −> db.demo488.insertOne({"Name":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351e0b0f3fa88e22790b2") } > db.demo488.insertOne({"Name":"David"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351e8b0f3fa88e22790b3") } > db.demo488.insertOne({"Name":"Bob"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351ebb0f3fa88e22790b4") } > db.demo488.insertOne({"Name":"Mike"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8351eeb0f3fa88e22790b5") } > db.demo488.insertOne({"Name":"Sam"});{ "acknowledged" : true, "insertedId" : ObjectId("5e835202b0f3fa88e22790b6") } > db.demo488.insertOne({"Name":"John"});{ "acknowledged" : true, "insertedId" : ObjectId("5e835207b0f3fa88e22790b7") } > db.demo488.insertOne({"Name":"Robert"});{ "acknowledged" : true, "insertedId" : ObjectId("5e83520cb0f3fa88e22790b8") }Display all ... Read More

575 Views
For a similar query to UNION two collections, use JOIN in MongoDB along with aggregate(). Let us create a collection with documents −> db.demo486.insertOne({_id:1, "Amount":30, "No":4}); { "acknowledged" : true, "insertedId" : 1 } > db.demo486.insertOne({_id:2, "Amount":40, "No":2}); { "acknowledged" : true, "insertedId" : 2 } > db.demo486.insertOne({_id:3, "Amount":60, "No":6}); { "acknowledged" : true, "insertedId" : 3 }Display all documents from a collection with the help of find() method −> db.demo486.find();This will produce the following output −{ "_id" : 1, "Amount" : 30, "No" : 4 } { "_id" : 2, "Amount" : 40, "No" : 2 } { "_id" ... Read More

3K+ Views
To check empty field in a MongoDB collection, use $exists along with $eq operator. Let us create a collection with documents −> db.demo485.insertOne({"FirstName":"Chris", "LastName":""});{ "acknowledged" : true, "insertedId" : ObjectId("5e82e9f6b0f3fa88e22790a8") } > db.demo485.insertOne({"FirstName":"David", "LastName":"Miller"});{ "acknowledged" : true, "insertedId" : ObjectId("5e82e9fdb0f3fa88e22790a9") } > db.demo485.insertOne({"FirstName":"Chris", "LastName":"Brown"});{ "acknowledged" : true, "insertedId" : ObjectId("5e82ea03b0f3fa88e22790aa") } > db.demo485.insertOne({"FirstName":"Robert", "LastName":""});{ "acknowledged" : true, "insertedId" : ObjectId("5e82ea0fb0f3fa88e22790ab") }Display all documents from a collection with the help of find() method −> db.demo485.find();This will produce the following output −{ "_id" : ObjectId("5e82e9f6b0f3fa88e22790a8"), "FirstName" : "Chris", "LastName" : "" } { "_id" ... Read More