- 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 6702 Articles for Database
83 Views
Let us create a collection with documents −> db.demo714.insertOne({FirstName:"Chris", LastName:"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2da85324c2c98cc4c2b") } > db.demo714.insertOne({FirstName:"Adam", LastName:"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2e585324c2c98cc4c2c") } > db.demo714.insertOne({FirstName:"David", LastName:"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2ed85324c2c98cc4c2d") } > db.demo714.insertOne({FirstName:"John", LastName:"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2f785324c2c98cc4c2e") }Display all documents from a collection with the help of find() method −> db.demo714.find();This will produce the following output −{ "_id" : ObjectId("5ea9a2da85324c2c98cc4c2b"), "FirstName" : "Chris", "LastName" : "Brown" } { "_id" : ObjectId("5ea9a2e585324c2c98cc4c2c"), "FirstName" : "Adam", "LastName" : "Smith" } { ... Read More
66 Views
Use $ along with update command to update tag records. Let us create a collection with documents −> db.demo713.insertOne( ... { ... tags: ... [ ... { ... id:101, ... Name:"Tag-1" ... }, ... { ... id:102, ... Name:"Tag-3" ... }, ... { ... ... Read More
408 Views
To add a new field, use $addFields in MongoDB. Let us create a collection with documents −> db.demo712.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f675d33e20ed1097b82") } > db.demo712.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f6a5d33e20ed1097b83") } > db.demo712.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f6e5d33e20ed1097b84") }Display all documents from a collection with the help of find() method −> db.demo712.find();This will produce the following output −{ "_id" : ObjectId("5ea85f675d33e20ed1097b82"), "Name" : "John" } { "_id" : ObjectId("5ea85f6a5d33e20ed1097b83"), "Name" : "Chris" } { "_id" : ObjectId("5ea85f6e5d33e20ed1097b84"), "Name" : "Bob" }Following is the query to add a ... Read More
1K+ Views
Let us create a collection with documents −> db.demo711.insertOne({Name:"John", "Marks":75, Age:21, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c215d33e20ed1097b7e") } > db.demo711.insertOne({Name:"Chris", "Marks":55, Age:22, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c2c5d33e20ed1097b7f") } > db.demo711.insertOne({Name:"Bob", "Marks":45, Age:20, status:"Inactive"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c3e5d33e20ed1097b80") } > db.demo711.insertOne({Name:"David", "Marks":85, Age:23, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c775d33e20ed1097b81") }Display all documents from a collection with the help of find() method −> db.demo711.find();This will produce the following output −{ "_id" : ObjectId("5ea85c215d33e20ed1097b7e"), "Name" : "John", "Marks" : 75, "Age" : 21, "status" : ... Read More
908 Views
The $natural returns the documents in natural order. To reverse the items, use $natural:-1. Let us create a collection with documents −> db.demo710.insertOne({id:101, Name:"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a855d33e20ed1097b7a") } > db.demo710.insertOne({id:102, Name:"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a8d5d33e20ed1097b7b") } > db.demo710.insertOne({id:103, Name:"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a935d33e20ed1097b7c") } > db.demo710.insertOne({id:104, Name:"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a9b5d33e20ed1097b7d") }Display all documents from a collection with the help of find() method −> db.demo710.find();This will produce the following output −{ "_id" : ObjectId("5ea83a855d33e20ed1097b7a"), "id" : 101, "Name" : ... Read More
104 Views
To get the sorted list of marks, use $sort. Use $limit: 2 to display only two such documents with least marks. Let us create a collection with documents −> db.demo709.insertOne({Name:"John", "Marks":75}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839005d33e20ed1097b76") } > db.demo709.insertOne({Name:"Chris", "Marks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839075d33e20ed1097b77") } > db.demo709.insertOne({Name:"David", "Marks":54}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839125d33e20ed1097b78") } > db.demo709.insertOne({Name:"Bob", "Marks":69}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839295d33e20ed1097b79") }Display all documents from a collection with the help of find() method −> db.demo709.find();This will produce the following output −{ "_id" ... Read More
1K+ Views
To find MongoDB based on a condition, use find() and set the condition. Let us create a collection with documents −> db.demo708.insertOne({"Name":"John", Marks:54}); { "acknowledged" : true, "insertedId" : ObjectId("5ea702e4d346dcb074dc6f33") } > db.demo708.insertOne({"Name":"Chris", Marks:35}); { "acknowledged" : true, "insertedId" : ObjectId("5ea702e6d346dcb074dc6f34") } > db.demo708.insertOne({"Name":"David", Marks:45}); { "acknowledged" : true, "insertedId" : ObjectId("5ea702ebd346dcb074dc6f35") } > db.demo708.insertOne({"Name":"Bob", Marks:40}); { "acknowledged" : true, "insertedId" : ObjectId("5ea702fad346dcb074dc6f36") }Display all documents from a collection with the help of find() method −> db.demo708.find();This will produce the following output −{ "_id" : ObjectId("5ea702e4d346dcb074dc6f33"), "Name" : "John", "Marks" : 54 ... Read More
289 Views
Let us create a collection with documents −> db.demo707.insertOne( ... { ... id:101, ... "serverInformation": ... [ ... { ... "IP":"192.56.34.3", ... "Status":"Active" ... }, ... { ... "IP":"192.56.36.4", ... "Status":"Inactive" ... } ... ] ... } ... ); { "acknowledged" : true, ... Read More
243 Views
Following is the syntax showing document and subdocument −db.yourCollectionName.insertOne( { yourFiledName:yourValue, yourFieldName : [ { yourFiledName1, yourFiledName2, . . . N } ] } );Let us see an example create a collection with documents −> db.demo706.insertOne( ... { ... PortalName: "GameApplication", ... Read More
249 Views
To query embedded documents in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo705.insertOne( ... { ... _id:101, ... "Information": ... [ ... { ... "StudentName":"Chris", ... "StudentAge":21 ... }, ... { ... "StudentName":"David", ... "StudentAge":23 ... }, ... { ... ... Read More