
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

252 Views
Following is the syntax to drop all indexes from all collections in a MongoDB database using command linedb.getCollectionNames().forEach(function(yourVariableName) { db.runCommand({dropIndexes: yourVariableName, index: "*"}); });The above syntax will drop all indexes except _id.Let us check the current database. Following is the query> dbThis will produce the following outputTestFollowing is the query to let us show some indexes from a collection before dropping indexes> db.indexingDemo.getIndexes();This will produce the following output[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", ... Read More

114 Views
To get all the MongoDB documents with some given criteria’s, following any of the below given casesCase 1 Following is the query to get all the documents without a single criterion using $ne operatordb.yourCollectionName.find({yourFieldName:{$ne:"yourValue"}}).pretty();Case 2 Following is the query to get all the documents without two given criterions using $nin operatordb.yourCollectionName.find({yourFieldName:{$nin:["yourValue1", "yourValue2"]}}).pretty();Let us first create a collection. Following is the query to create a collection with documents>db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Larry", "StudentSubjectName":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5c993d82330fd0aa0d2fe4d2") } >db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Chris", "StudentSubjectName":"C++"}); { "acknowledged" : true, "insertedId" : ObjectId("5c993d8f330fd0aa0d2fe4d3") } >db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Robert", "StudentSubjectName":"C"}); { "acknowledged" : true, "insertedId" : ObjectId("5c993d99330fd0aa0d2fe4d4") } ... Read More

4K+ 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

129 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

141 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

236 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

126 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

201 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

547 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

283 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