- Trending Categories
- 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 1659 Articles for Big Data Analytics
3K+ Views
Let us first create a collection. Following is the query to create a collection with documents> db.documentExistsOrNotDemo.insertOne({"UserId":101, "UserName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9932bd330fd0aa0d2fe4cf") } > db.documentExistsOrNotDemo.insertOne({"UserId":102, "UserName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9932c6330fd0aa0d2fe4d0") } > db.documentExistsOrNotDemo.insertOne({"UserId":102, "UserName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9932ce330fd0aa0d2fe4d1") }Following is the query to display all the documents from a collection with the help of find() method> db.documentExistsOrNotDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5c9932bd330fd0aa0d2fe4cf"), "UserId" : 101, "UserName" : "John" } { "_id" : ObjectId("5c9932c6330fd0aa0d2fe4d0"), "UserId" : 102, ... Read More
84 Views
To clear items in a nested array, use the $set operator. Let us first create a collection. Following is the query to create a collection with documents> db.clearingItemsInNestedArrayDemo.insertOne( { ... ... "StudentName" : "John", ... "StudentDetails" : [ ... { ... "ProjectName" : "Online Banking", ... "ProjectDetails" : [ ... { ... "TechnologyUsed" : "Java", ... "TeamSize":5 ... }, ... ... ... Read More
90 Views
Search for a text in MongoDBs Double Nested Array with the help of dot(.) notation. Let us first create a collection. Following is the query to create a collection with documents> db.doubleNestedArrayDemo.insertOne( ... { ... "StudentId" : "1000", ... "StudentName" : "Larry", ... "StudentDetails" : [ ... { ... "ProjectName" : "Online Banking", ... "ProjectDetails" : [ ... { ... ... Read More
210 Views
To add a new item to an array, you can use $push operator. Let us first implement the following query to create a collection with documents:> db.updateDemo.insertOne({"StudentName":"Larry", "StudentCoreSubject":["Java", "C"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98ba78330fd0aa0d2fe4c9") } >db.updateDemo.insertOne({"StudentName":"Robert", "StudentCoreSubject":["C++", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98ba8b330fd0aa0d2fe4ca") } > db.updateDemo.insertOne({"StudentName":"Chris", "StudentCoreSubject":["Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98ba9b330fd0aa0d2fe4cb") }Following is the query to display all the documents from a collection with the help of find() method> db.updateDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5c98ba78330fd0aa0d2fe4c9"), "StudentName" : "Larry", "StudentCoreSubject" : [ ... Read More
71 Views
To get a distinct aggregation of an array field across indexes, let us take an example and create a collection with some documents.Following is the query to create a collection with documents> db.distinctAggregation.insertOne({"UserName":"Larry", "UserPost":["Hi", "Hello"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98aefb330fd0aa0d2fe4c6") } > db.distinctAggregation.insertOne({"UserName":"Chris", "UserPost":["Hi", "Good Morning"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98af0a330fd0aa0d2fe4c7") } > db.distinctAggregation.insertOne({"UserName":"Robert", "UserPost":["Awesome"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c98af1e330fd0aa0d2fe4c8") }Following is the query to display all documents from a collection with the help of find() method> db.distinctAggregation.find().pretty();This will produce the following output{ "_id" : ObjectId("5c98aefb330fd0aa0d2fe4c6"), ... Read More
157 Views
To get only the FALSE value, let us first create a collection with documents. One of the fields is isEnable that is having TRUE or FALSE values as shown below> db.translateDefinitionDemo.insertOne({"_id":10, "StudentName":"Larry", "isEnable":true}); { "acknowledged" : true, "insertedId" : 10 } > db.translateDefinitionDemo.insertOne({"_id":20, "StudentName":"Chris", "isEnable":false}); { "acknowledged" : true, "insertedId" : 20 } > db.translateDefinitionDemo.insertOne({"_id":30, "StudentName":"Robert", "isEnable":true}); { "acknowledged" : true, "insertedId" : 30 } > db.translateDefinitionDemo.insertOne({"_id":40, "StudentName":"Sam", "isEnable":false}); { "acknowledged" : true, "insertedId" : 40 } > db.translateDefinitionDemo.insertOne({"_id":50, "StudentName":"Mike", "isEnable":true}); { "acknowledged" : true, "insertedId" : 50 }Following is the query to display all the documents from a collection ... Read More
440 Views
To get all the collections from all the databases, let us first get all the databases using the following query> switchDatabaseAdmin = db.getSiblingDB("admin"); admin > allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases;This will produce the following output[ { "name" : "admin", "sizeOnDisk" : 495616, "empty" : false }, { "name" : "config", "sizeOnDisk" : 98304, "empty" : false }, { "name" : "local", "sizeOnDisk" : 73728, "empty" : false ... Read More
193 Views
Following is the syntax to get the embedded data in a MongoDB documentdb.yourCollectionName.find({}, {‘yourOuterKeyName.yourInnerKeyName:1}).pretty();Let us first create a collection with documents> db.embeddedCollectionDemo.insertOne( ... { ... "StudentName" : "Larry", ... "StudentDetails": { ... "Larry1234": {"ProjectName": "Student Web Tracker"}, ... "Larry7645": {"ProjectName": "Hospital Management System"}, ... "Larry9879": {"ProjectName": "Library Management System"}, ... ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5c98a100330fd0aa0d2fe4c5") }Following is the query to display all documents from a collection> db.embeddedCollectionDemo.find().pretty();This ... Read More
496 Views
Yes, you can get the first item in a cursor object using findOne() method. Following is the syntaxdb.yourCollectionName.findOne();However, the following syntax is used if you want a single document in a cursor objectdb.yourCollectionName.findOne({yourCondition});We will first create a collection. Following is the query to create a collection with documents> db.getFirstItemDemo.insertOne({"CustomerName":"Chris", "CustomerAge":28}); { "acknowledged" : true, "insertedId" : ObjectId("5c989059330fd0aa0d2fe4c1") } > db.getFirstItemDemo.insertOne({"CustomerName":"Larry", "CustomerAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c989063330fd0aa0d2fe4c2") } > db.getFirstItemDemo.insertOne({"CustomerName":"Robert", "CustomerAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5c98906d330fd0aa0d2fe4c3") } > db.getFirstItemDemo.insertOne({"CustomerName":"David", "CustomerAge":39}); { "acknowledged" : true, "insertedId" : ObjectId("5c989081330fd0aa0d2fe4c4") }Following is ... Read More
331 Views
It is not possible to return only embedded document. However, it will return all the documents from a collection. Let us first implement the following query to create a collection with documents>db.queryToEmbeddedDocument.insertOne({"UserName":"Larry", "PostDetails":[{"UserMessage":"Hello", "UserLikes":8}, {"UserMessage":"Hi", "UserLikes":6}, {"UserMessage":"Good Morning", "UserLikes":12}, {"UserMessage":"Awesome", "UserLikes":4}]}); { "acknowledged" : true, "insertedId" : ObjectId("5c988a9f330fd0aa0d2fe4bd") }Following is the query to display all documents from a collection with the help of find() method> db.queryToEmbeddedDocument.find().pretty();This will produce the following output{ "_id" : ObjectId("5c988a9f330fd0aa0d2fe4bd"), "UserName" : "Larry", "PostDetails" : [ { "UserMessage" : "Hello", ... Read More