Found 1659 Articles for Big Data Analytics

Display MongoDB explain query plan?

AmitDiwan
Updated on 27-Mar-2020 10:28:00

295 Views

For information on query plan, use explain() in MongoDB. Let us create a collection with documents −> db.demo202.insertOne({"StudentFirstName":"Chris", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c3bd103d395bdc21346e8") } > db.demo202.insertOne({"StudentFirstName":"David", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c3bd803d395bdc21346e9") } > db.demo202.insertOne({"StudentFirstName":"Bob", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c3bde03d395bdc21346ea") }Display all documents from a collection with the help of find() method −> db.demo202.find();This will produce the following output −{ "_id" : ObjectId("5e3c3bd103d395bdc21346e8"), "StudentFirstName" : "Chris", "StudentAge" : 21 } { "_id" : ObjectId("5e3c3bd803d395bdc21346e9"), "StudentFirstName" : "David", "StudentAge" : 23 } { "_id" : ObjectId("5e3c3bde03d395bdc21346ea"), "StudentFirstName" ... Read More

Update only a specific value in a MongoDB document

AmitDiwan
Updated on 27-Mar-2020 10:21:19

199 Views

To update only a specific value, use update() and in that set the new value using $set. Let us create a collection with documents −> db.demo201.insertOne({"ClientName":"Chris Brown", "ClientAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c39ca03d395bdc21346e5") } > db.demo201.insertOne({"ClientName":"David Miller", "ClientAge":35}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c39d403d395bdc21346e6") } > db.demo201.insertOne({"ClientName":"Carol Taylor", "ClientAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c39e603d395bdc21346e7") }Display all documents from a collection with the help of find() method −> db.demo201.find();This will produce the following output −{ "_id" : ObjectId("5e3c39ca03d395bdc21346e5"), "ClientName" : "Chris Brown", "ClientAge" : 26 } { "_id" : ObjectId("5e3c39d403d395bdc21346e6"), ... Read More

MongoDB filter multiple sub-documents?

AmitDiwan
Updated on 27-Mar-2020 10:19:11

378 Views

To filter multiple sub-documents in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo200.insertOne( ...   { ...      "Id":"101", ...      "details1":[ ...         { ...            "isActive":true, ...            "SubjectName":"MySQL" ...         }, { ...            "isActive":false, ...            "SubjectName":"Java" ...         } ...      ], ...      "details2":[ ...         { ...            "isActive":false, ...     ... Read More

Aggregation in MongoDB for nested documents?

AmitDiwan
Updated on 27-Mar-2020 10:11:46

225 Views

For aggregation in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo199.insertOne( ...   { ...      "details1":{ ...         "details2":{ ...            "details3":{ ...               "Name":"Chris", ...               "details4":{ ...                  "details5":{ ...                     "v1":10, ...                     "v2":20, ...                     "v3":30 ... ... Read More

MongoDB query to $pull / $unset with multiple conditions?

AmitDiwan
Updated on 27-Mar-2020 10:07:19

268 Views

For this, use $pull along with update. Let us create a collection with documents −> db.demo198.insertOne({"List":{"Values":[10, 20, 30, 30, 70, 80, 90]}}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c224503d395bdc21346df") } > db.demo198.insertOne({"List":{"Values":[56, 978, 56, 34, 23, 34]}}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c225403d395bdc21346e0") } > db.demo198.insertOne({"List":{"Values":[21, 12, 14, 15, 34, 56]}}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3c226603d395bdc21346e1") }Display all documents from a collection with the help of find() method −> db.demo198.find();This will produce the following output −{ "_id" : ObjectId("5e3c224503d395bdc21346df"), "List" : { "Values" : [ 10, 20, 30, 30, 70, 80, ... Read More

In MongoDB will limit() increase query speed?

AmitDiwan
Updated on 27-Mar-2020 10:04:51

78 Views

No, using LIMIT() decreases the bandwidth consumption and it does not increase query speed. Let us see an example and create a collection with documents −> db.demo197.insertOne({"Name":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afde803d395bdc21346d8") } > db.demo197.insertOne({"Name":"Bob"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afdef03d395bdc21346d9") } > db.demo197.insertOne({"Name":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afdf203d395bdc21346da") } > db.demo197.insertOne({"Name":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afdf603d395bdc21346db") } > db.demo197.insertOne({"Name":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afdf903d395bdc21346dc") } > db.demo197.insertOne({"Name":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3afe1603d395bdc21346dd") } > db.demo197.insertOne({"Name":"John"}); { ... Read More

Update key value where different key equals some value in MongoDB?

AmitDiwan
Updated on 27-Mar-2020 10:01:56

435 Views

Let us create a collection with documents −> db.demo196.insertOne( ...   { ... ...      "Id" : "101", ...      "details" : [ ...         { ...            "FirstName" : "Chris", ...            "LastName" : "Brown", ...            "Score" : 45 ...         }, ...         { ...            "FirstName" : "David", ...            "LastName" : "Miller", ...            "Score" : 87 ...     ... Read More

Is it possible to return a list of specific values from a query in MongoDB?

AmitDiwan
Updated on 27-Mar-2020 09:57:42

327 Views

To return a list of specific values, use map(). Let us create a collection with documents −> db.demo195.insertOne({"Subject":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3af3f203d395bdc21346d4") } > db.demo195.insertOne({"Subject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3af3f703d395bdc21346d5") } > db.demo195.insertOne({"Subject":"Java"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3af3fa03d395bdc21346d6") }Display all documents from a collection with the help of find() method −> db.demo195.find();This will produce the following output −{ "_id" : ObjectId("5e3af3f203d395bdc21346d4"), "Subject" : "MySQL" } { "_id" : ObjectId("5e3af3f703d395bdc21346d5"), "Subject" : "MongoDB" } { "_id" : ObjectId("5e3af3fa03d395bdc21346d6"), "Subject" : "Java" }Following is the query to return a ... Read More

MongoDB query in object of arrays

AmitDiwan
Updated on 27-Mar-2020 09:55:41

133 Views

Let us first create a collection with documents −> db.demo194.insertOne( ...   { ...      "_id": 101, ...      "details": { ...         "otherDetails": { ...            "List1": ["MongoDB", "MySQL"], ...            "List2": ["Java"], ...            "List3": ["MongoDB", "C"] ...         } ...      } ...   } ...); { "acknowledged" : true, "insertedId" : 101 } > db.demo194.insertOne( {"_id": 102, "details": { "otherDetails": { "List1": ["Java", "C"],        "List2": ["C++"], "List3": ["Python", "Spring"] } } } ... Read More

How to improve the execution time of a query in MongoDB?

AmitDiwan
Updated on 27-Mar-2020 08:34:54

163 Views

To improve the execution time of a query, use index along with unique:true. Let us create a collection with documents −> db.demo193.createIndex({"LastName":1}, {unique:true}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 } > db.demo193.insertOne({"FirstName":"John", "LastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3ade1803d395bdc21346d1") } > db.demo193.insertOne({"FirstName":"John", "LastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3ade1f03d395bdc21346d2") } > db.demo193.insertOne({"FirstName":"David", "LastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e3ade2803d395bdc21346d3") }Display all documents from a collection with the help of find() method −> db.demo193.find();This will produce the following output −{ "_id" ... Read More

Advertisements