- 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
265 Views
You can use $lte operator along with Date() for this. Let us first create a collection with documents. Here, we have set the date 2019-05-11, which is the current date −> db.getDocumentsExpiredDemo.insertOne({"ArrivalDate":new ISODate("2019-05-11")}); { "acknowledged" : true, "insertedId" : ObjectId("5cd563b17924bb85b3f4893b") } > db.getDocumentsExpiredDemo.insertOne({"ArrivalDate":new ISODate("2019-01-01")}); { "acknowledged" : true, "insertedId" : ObjectId("5cd563bf7924bb85b3f4893c") } > db.getDocumentsExpiredDemo.insertOne({"ArrivalDate":new ISODate("2019-05-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5cd563ca7924bb85b3f4893d") } > db.getDocumentsExpiredDemo.insertOne({"ArrivalDate":new ISODate("2019-02-01")}); { "acknowledged" : true, "insertedId" : ObjectId("5cd563e77924bb85b3f4893e") }Following is the query to display all documents from a collection with the help of find() method −> db.getDocumentsExpiredDemo.find().pretty();This ... Read More
293 Views
To update array in MongoDB document by variable index, use the below syntax. Here, yourIndexValue in the index value, where yourIndexVariableName is the variable name for index −var yourIndexVariableName= yourIndexValue, anyVariableName= { "$set": {} }; yourVariableName["$set"]["yourFieldName."+yourIndexVariableName] = "yourValue"; db.yourCollectionName.update({ "_id": yourObjectId}, yourVariableName);Let us first create a collection with documents −> db.updateByVariableDemo.insertOne({"StudentSubjects":["MySQL", "Java", "SQL Server", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd553c37924bb85b3f4893a") }Following is the query to display all documents from a collection with the help of find() method −> db.updateByVariableDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd553c37924bb85b3f4893a"), "StudentSubjects" : [ ... Read More
94 Views
You can use map() for this. Let us first create a collection with documents −> db.deleteDemo.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd550492cba06f46efe9f06") } > db.deleteDemo.insertOne({"Name":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5504d2cba06f46efe9f07") } > db.deleteDemo.insertOne({"Name":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd550512cba06f46efe9f08") } > db.deleteDemo.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5505d2cba06f46efe9f09") } > db.deleteDemo.insertOne({"Name":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd550682cba06f46efe9f0a") } > db.deleteDemo.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5506f2cba06f46efe9f0b") } > db.deleteDemo.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd550752cba06f46efe9f0c") } > db.deleteDemo.insertOne({"Name":"Bob"}); ... Read More
397 Views
You can use $and operator. Let us first create a collection with documents −>db.selectingASingleFieldDemo.insertOne({"StudentFirstName":"John", "StudentAge":23, "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd547142cba06f46efe9f02") } >db.selectingASingleFieldDemo.insertOne({"StudentFirstName":"Carol", "StudentAge":21, "StudentCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5471f2cba06f46efe9f03") } >db.selectingASingleFieldDemo.insertOne({"StudentFirstName":"David", "StudentAge":24, "StudentCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5472c2cba06f46efe9f04") } >db.selectingASingleFieldDemo.insertOne({"StudentFirstName":"Robert", "StudentAge":26, "StudentCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd548382cba06f46efe9f05") }Following is the query to display all documents from a collection with the help of find() method −> db.selectingASingleFieldDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd547142cba06f46efe9f02"), "StudentFirstName" : "John", "StudentAge" : ... Read More
215 Views
You can use aggregate framework for this. Let us first create a collection with documents −>db.aggregationOperatorDemo.insertOne({"FirstValue":392883,"SecondValue":10000000000}); { "acknowledged" : true, "insertedId" : ObjectId("5cd541452cba06f46efe9f01") }Following is the query to display all documents from a collection with the help of find() method −> db.aggregationOperatorDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd541452cba06f46efe9f01"), "FirstValue" : 392883, "SecondValue" : 10000000000 }Following is the query to use divide aggregation operator −> db.aggregationOperatorDemo.aggregate([ ... { "$project": { "Value": { "$divide": ["$FirstValue", "$SecondValue"] } } } ... ]);This will produce the following output −{ "_id" : ObjectId("5cd541452cba06f46efe9f01"), "Value" : 0.0000392883 }
159 Views
Let us first create a collection with documents −> db.searchAnArrayDemo.insertOne({_id:1, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 1 } > db.searchAnArrayDemo.insertOne({_id:2, "TechnicalDetails":[{"Language":"MySQL"}]}); { "acknowledged" : true, "insertedId" : 2 } > db.searchAnArrayDemo.insertOne({_id:3, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 3 } > db.searchAnArrayDemo.insertOne({_id:4, "TechnicalDetails":[{"Language":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : 4 } > db.searchAnArrayDemo.insertOne({_id:5, "TechnicalDetails":[{"Language":"Java"}]}); { "acknowledged" : true, "insertedId" : 5 }Following is the query to display all documents from a collection with the help of find() method −> db.searchAnArrayDemo.find().pretty();This will produce the following output −{ "_id" : 1, "TechnicalDetails" : [ { "Language" : "MongoDB" } ] } ... Read More
119 Views
To update the inner field, use the below syntax −db.yourCollectionName.update({"_id" : yourObjectId}, {$set : {"yourOuterFieldName.yourInnerFieldName" :yourValue}});Let us first create a collection with documents −> db.updateDocumentDemo.insertOne( ... { ... ... "StudentDetails" : { ... "StudentFirstName" : "Adam", ... "StudentLastName" : "Samith" ... }, ... "StudentOtherDetails" : { ... "StudentFavouriteSubject" : "MySQL", ... "StudentScore" : 45 ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd50bb32cba06f46efe9efe") }Following is the query to ... Read More
56 Views
You can use $set operator along with update(). Let us first create a collection with documents −> db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd506fe2cba06f46efe9efa") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd507022cba06f46efe9efb") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd507022cba06f46efe9efc") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd507032cba06f46efe9efd") }Following is the query to display all documents from a collection with the help of find() method −> db.workingOfUpdateMethod.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd506fe2cba06f46efe9efa"), "ClientCountryName" ... Read More
98 Views
You can use dot(.) notation for this. Let us first create a collection with documents −>db.containsTrueValueDemo.insertOne({"IsMarried":[true, false, true, true, true, true, false, true, false, false, true]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd5039c2cba06f46efe9ef5") }Following is the query to display all documents from a collection with the help of find() method −> db.containsTrueValueDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd5039c2cba06f46efe9ef5"), "IsMarried" : [ true, false, true, true, true, true, false, true, ... Read More
270 Views
You can use $or operator along with find() for this. Let us first create a collection with documents −> db.findDocumentWithFilterDemo.insertOne({"ClientName":"Robert", "IsMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cd4fd1e2cba06f46efe9ef1") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"Chris", "IsMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cd4fd322cba06f46efe9ef2") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"David", "IsMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cd4fd3b2cba06f46efe9ef3") } > db.findDocumentWithFilterDemo.insertOne({"ClientName":"Carol", "IsMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cd4fd452cba06f46efe9ef4") }Following is the query to display all documents from a collection with the help of find() method −> db.findDocumentWithFilterDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd4fd1e2cba06f46efe9ef1"), "ClientName" ... Read More