- 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)
309 Views
For this, use find() and fetch a specific record. Let us create a collection with documents −> db.demo30.insertOne({"City":"New York"}); { "acknowledged" : true, "insertedId" : ObjectId("5e174ceccfb11e5c34d898bd") } > db.demo30.insertOne({"City":"Los Angeles"}); { "acknowledged" : true, "insertedId" : ObjectId("5e174d0ecfb11e5c34d898be") } > db.demo30.insertOne({"City":"Chicago"}); { "acknowledged" : true, "insertedId" : ObjectId("5e174d18cfb11e5c34d898bf") } > db.demo30.insertOne({"City":"Los Angeles"}); { "acknowledged" : true, "insertedId" : ObjectId("5e174d1dcfb11e5c34d898c0") }Display all documents from a collection with the help of find() method −> db.demo30.find();This will produce the following output −{ "_id" : ObjectId("5e174ceccfb11e5c34d898bd"), "City" : "New York" } { "_id" : ObjectId("5e174d0ecfb11e5c34d898be"), "City" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
195 Views
To get array items in a MongoDB document, use the dot(.) notation. Let us create a collection with documents −> db.demo29.insertOne({"StudentDetails":[{"StudentName":"Chris", "StudentMarks":58}, {"StudentName":"Bob", "StudentMarks":69}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e15fcc08f2315c2efc48e6e") } >db.demo29.insertOne({"StudentDetails":[{"StudentName":"David", "StudentMarks":97}, {"StudentName":"Carol", "StudentMarks":96}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e15fcd38f2315c2efc48e6f") }Display all documents from a collection with the help of find() method −> db.demo29.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e15fcc08f2315c2efc48e6e"), "StudentDetails" : [ { "StudentName" : "Chris", "StudentMarks" : 58 }, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
187 Views
Yes, we can use the “.” symbol in MongoDB collection name. Let us create a collection with documents −> db.getCollection('demo28.example'); web.demo28.example > > > db.getCollection('demo28.example').insertOne({"Name":"Chris", "Age":32}); { "acknowledged" : true, "insertedId" : ObjectId("5e15fbe48f2315c2efc48e6b") } > db.getCollection('demo28.example').insertOne({"Name":"Bob", "Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e15fbec8f2315c2efc48e6c") } > db.getCollection('demo28.example').insertOne({"Name":"David", "Age":33}); { "acknowledged" : true, "insertedId" : ObjectId("5e15fbf38f2315c2efc48e6d") }Display all documents from a collection with the help of find() method −> db.getCollection('demo28.example').find().pretty();This will produce the following output −{ "_id" : ObjectId("5e15fbe48f2315c2efc48e6b"), "Name" : "Chris", "Age" : 32 } { "_id" : ObjectId("5e15fbec8f2315c2efc48e6c"), "Name" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
226 Views
Yes, it is possible using the UPDATE() method. Let us create a collection with documents −> db.demo27.insertOne({"StudentDetails":{"101":{"Subject":["Java"]}}}); { "acknowledged" : true, "insertedId" : ObjectId("5e15f9e822d07d3b95082e7f") } > db.demo27.insertOne({"StudentDetails":{"101":{"Subject":["MySQL"]}}}); { "acknowledged" : true, "insertedId" : ObjectId("5e15f9eb22d07d3b95082e80") }Display all documents from a collection with the help of find() method −> db.demo27.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e15f9e822d07d3b95082e7f"), "StudentDetails" : { "101" : { "Subject" : [ "Java" ] } } } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
121 Views
For similar operation, you can use / searchLetter /. Let us first create a collection with documents −> db.demo26.insertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c9dc22d07d3b95082e79") } > db.demo26.insertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c9e022d07d3b95082e7a") } > db.demo26.insertOne({"StudentName":"Jones"}); { "acknowledged" : true, "insertedId" : ObjectId("5e14ca7222d07d3b95082e7b") } > db.demo26.insertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e14ca7622d07d3b95082e7c") }Display all documents from a collection with the help of find() method −> db.demo26.find();This will produce the following output −{ "_id" : ObjectId("5e14c9dc22d07d3b95082e79"), "StudentName" : "Chris" } { "_id" : ObjectId("5e14c9e022d07d3b95082e7a"), "StudentName" : "John" } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
120 Views
To query from part of object in an array, use $findOne() and $all. Let us first create a collection with documents −> db.demo25.insertOne( ... { ... ... "Details":[ ... { ... "UserId":"Carol101", ... "UserName":"Carol" ... }, ... { ... "UserId":"David102", ... "UserName":"David" ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e14c86e22d07d3b95082e77") } > db.demo25.insertOne( ... { ... ... "Details":[ ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
185 Views
To push a computed expression in $group, use aggregate. Let us first create a collection with documents −> db.demo24.insertOne({"Id":100, "Status":true}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c58722d07d3b95082e72") } > db.demo24.insertOne({"Id":100, "Status":true}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c58a22d07d3b95082e73") } > db.demo24.insertOne({"Id":100, "Status":false}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c58f22d07d3b95082e74") } > db.demo24.insertOne({"Id":100, "Status":true}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c59122d07d3b95082e75") } > db.demo24.insertOne({"Id":100, "Status":false}); { "acknowledged" : true, "insertedId" : ObjectId("5e14c59222d07d3b95082e76") }Display all documents from a collection with the help of find() method −> db.demo24.find();This will produce the following output ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
540 Views
For sub array document in MongoDB, use aggregate along with $sort. Let us first create a collection with documents −> db.demo23.insertOne( ...{ ... ... "StudentDetails" : [{ ... "Name" : "David", ... "Age" : 23, ... ... }, { ... "Name" : "Adam", ... "Age" : 24, ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e14c3eb22d07d3b95082e71") }Display all documents from a collection with the help of find() method −> db.demo23.find().pretty()This will produce the following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
284 Views
To sort values, use sort() in MongoDB. Let us first create a collection with documents −> db.demo365.insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57d5b6d0ada61456dc936f") } > db.demo365.insertOne({"FirstName":"Adam"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57d5bad0ada61456dc9370") } > db.demo365.insertOne({"FirstName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57d5bed0ada61456dc9371") } > db.demo365.insertOne({"FirstName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57d5c0d0ada61456dc9372") }Display all documents from a collection with the help of find() method −> db.demo365.find();This will produce the following output −{ "_id" : ObjectId("5e57d5b6d0ada61456dc936f"), "FirstName" : "Chris" } { "_id" : ObjectId("5e57d5bad0ada61456dc9370"), "FirstName" : "Adam" } { "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
611 Views
For this, use $addFields. In that, use the $objectToArray to get the data in the form of keys and values. Use $filter with $indexOfBytes to check if there are any keys with. inside it.Let us first create a collection with documents −> db.demo364.insertOne( ... { ... "details" : { ... "details1.otherdetails.Name" : {"FirstName":"Chris" } ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e57d485d0ada61456dc936d") } > db.demo364.insertOne( ... { ... "details" : { ... "details1.otherdetails.Name" ... Read More