

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is there any way in MongoDB to get the inner value of json data?
To get inner value of JSON data, use find() along with dot(.) notation. Let us create a collection with documents −
> db.demo235.insertOne( ... { ... "id":101, ... "details":[ ... { ... "Name":"Chris Brown", ... "Age":21 ... }, ... { ... "Name":"David Miller", ... "Age":24 ... } ... ], ... "otherdetails":[ ... { ... "Score":56, ... "Subject":"MongoDB" ... }, ... { ... "Score":78, ... "Subject":"MySQL" ... } ... ] ... } ...); { "acknowledged" : true, "insertedId" : ObjectId("5e418d22f4cebbeaebec514b") }
Display all documents from a collection with the help of find() method −
> db.demo235.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e418d22f4cebbeaebec514b"), "id" : 101, "details" : [ { "Name" : "Chris Brown", "Age" : 21 }, { "Name" : "David Miller", "Age" : 24 } ], "otherdetails" : [ { "Score" : 56, "Subject" : "MongoDB" }, { "Score" : 78, "Subject" : "MySQL" } ] }
Following is the query to get the inner value of json data −
> db.demo235.find({},{"otherdetails.Subject":1,_id:0});
This will produce the following output −
{ "otherdetails" : [ { "Subject" : "MongoDB" }, { "Subject" : "MySQL" } ] }
- Related Questions & Answers
- Is there any way to skip some documents in MongoDB?
- Is there any way to see the MongoDB results in a better format?
- Is there any way to use values from a JSON object in a MySQL Select statement?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Is there a way to list collections in MongoDB?
- Accessing inner element of JSON array in MongoDB?
- Is there a way to retrieve the minimum value of fields in MySQL?
- How to only get the data of the nested JSON object in MongoDB?
- Is there a way to limit the number of records in a certain MongoDB collection?
- Is there any way to embed a PDF file into an HTML5 page?
- Is there any way of moving to HTML 5 and still promise multi browser compatibility?
- Get value of any attribute from XML data in JavaScript?
- Is there any easy way to add multiple records in a single MySQL query?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- Is there any way I can call the validate() function outside the initValidation() function in JavaScript?
Advertisements