- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
236 Views
Use forEach and check for the different elements and use save() along with some condition. Let us create a collection with documents −> db.demo646.insertOne( ... { ... ... "Information": [ ... { id: 100, Name:"Chris" }, ... { id: 100, Name:"Chris" }, ... { id: 101, Name:"David" }, ... { id: 100, Name:"Chris" } ... ], ... "different": [] ... } ... ) { "acknowledged" : true, "insertedId" : ObjectId("5e9c82ec6c954c74be91e6ed") }Display ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
455 Views
To store, let us see an example and create a collection with documents −> db.demo645.insertOne( ... { ... 'fileName' : 'MongoDB Program', ... 'fileLocation':'C:/users/workspace/AllMongoDBProgram/MongoDB Program' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e8") } > > db.demo645.insertOne( ... { ... 'fileName' : 'SumOfTwoNumbers.java', ... 'fileLocation':'E:/eclipseWorkspace/AllJavaPrograms/SumOfTwoNumbers.java' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e9") } > db.demo645.insertOne( ... { ... 'fileName' : 'Script.sql', ... 'fileLocation':'C:/MySQLQuery/Script.sql' ... } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To update, use update() in MongoDB. To set it to current date, you need to get the current date −var todayDate = new Date();Let us first create a collection with documents −> db.demo644.insertOne({"ShippingDate":new ISODate("2018-04-19")}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c76896c954c74be91e6e6") } > db.demo644.insertOne({"ShippingDate":new ISODate("2019-01-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c76966c954c74be91e6e7") }Display all documents from a collection with the help of find() method −> db.demo644.find();This will produce the following output −{ "_id" : ObjectId("5e9c76896c954c74be91e6e6"), "ShippingDate" : ISODate("2018-04-19T00:00:00Z") } { "_id" : ObjectId("5e9c76966c954c74be91e6e7"), "ShippingDate" : ISODate("2019-01-10T00:00:00Z") }Following is the query to update timestamp −> var todayDate ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
872 Views
To update bested documents in MongDB, use UPDATE() and positional($) operator. Let us create a collection with documents −> db.demo643.insertOne({ ... details : [ ... { ... "CountryName":"US", ... StudentDetails:[{Name:"Chris"}, {SubjectName:"MySQL"}] ... }, ... ... { ... "CountryName":"UK", ... StudentDetails:[{Name:"Bob"}, {SubjectName:"Java"}] ... } ... ] ... } ... ) { "acknowledged" : true, "insertedId" : ObjectId("5e9c737f6c954c74be91e6e3") }Display all documents from a collection with the help of find() method ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
203 Views
For this, use $all. The $all operator selects the documents where the value of a field is an array that contains all the specified elements. Let us create a collection with documents −> db.demo642.insertOne( ... { ... _id:1, ... ListOfNames:["Robert", "John"] ... } ... ); { "acknowledged" : true, "insertedId" : 1 } > db.demo642.insertOne( { _id:2, ListOfNames:["Robert", "Chris"] } ); { "acknowledged" : true, "insertedId" : 2 }Display all documents from a collection with the help of find() method −> db.demo642.find();This will produce the following output −{ "_id" : 1, "ListOfNames" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
124 Views
To list collections, use getCollectionNames() in MongoDB. Following is the syntax −db.getCollectionNames();Let us implement the above syntax in order to list all collection names from the test database −> db.getCollectionNames();This will produce the following output −[ "arrayDemo", "arrayFieldIsNotEmptyDemo", "characterInFieldsDemo", "checkFieldExistDemo", "compareTwoFields", "comparingTwoFieldsDemo", "convertTextToDateTypeDemo", "countGroupByDemo", "demo407", "demo408", "demo409", "demo410", "demo411", "demo412", "demo413", "demo414", "demo415", "demo416", "demo417", "demo418", "demo419", "demo543", "demo544", "demo545", "demo546", "demo547", "demo548", "demo549", "demo550", "demo551", "demo552", "demo553", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
342 Views
To get specific elements, use $match with dot notation. Let us create a collection with documents −> db.demo641.insert( ... { ... ProductId:101, ... "ProductInformation": ... ( [ ... { ... ProductName:"Product-1", ... "ProductPrice":1000 ... }, ... { ... ProductName:"Product-2", ... "ProductPrice":500 ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
546 Views
If you want the first element from array, you can use $slice along with $gte. Let us create a collection with documents −> db.demo640.insertOne({Name:"John", "Scores":[80, 90, 75]}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c2eb86c954c74be91e6e0") } > db.demo640.insertOne({Name:"Chris", "Scores":[85, 70, 89]}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c2ece6c954c74be91e6e1") }Display all documents from a collection with the help of find() method −> db.demo640.find();This will produce the following output −{ "_id" : ObjectId("5e9c2eb86c954c74be91e6e0"), "Name" : "John", "Scores" : [ 80, 90, 75 ] } { "_id" : ObjectId("5e9c2ece6c954c74be91e6e1"), "Name" : "Chris", "Scores" : [ 85, 70, 89 ] }Following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
99 Views
For this, use $group in MongoDB aggregation. Let us create a collection with documents −> db.demo639.insertOne( ... { ... "_id" : 1, ... "CountryName" : "US", ... "Info1" : { ... "Name" : "Chris", ... "SubjectName" : "MySQL", ... "Marks" : 78 ... }, ... "Info2" : { ... "Name" : "Chris", ... "SubjectName" : "MySQL", ... "Marks" : 78 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
420 Views
To filter items by fields and subfields, use dot notation. Let us create a collection with documents −> db.demo638.insert({Name:"Chris"}); WriteResult({ "nInserted" : 1 }) > db.demo638.insert({Name:"David", details:{Subject:"MongoDB"}}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo638.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e9c28666c954c74be91e6de"), "Name" : "Chris" } { "_id" : ObjectId("5e9c28866c954c74be91e6df"), "Name" : "David", "details" : { "Subject" : "MongoDB" } }Following is the query to filter items by multiple fields and subfields −> ... Read More