How to show table data in MongoDB




Asked on September 20, 2019
How to show table data in MongoDB?


Replied on September 20, 2019
1. Suppose your database name is myDB. Go to your database. 

> use myDB


2. Display all tables.

> show tables

The output will be all tables available in myDB database.


3. Suppose we have a employee table in our MongoDB database. Now display all data of this table using find().

> db.employee.find()
{ "_id" : 1, "name" : "Ram", "age" : 20, "_class" : "com.test.mongodb.entity.Employee" }
{ "_id" : 2, "name" : "Shyam", "age" : 19, "_class" : "com.test.mongodb.entity.Employee" }
{ "_id" : 3, "name" : "Mohan", "age" : 20, "_class" : "com.test.mongodb.entity.Employee" }
{ "_id" : 4, "name" : "Krishn", "age" : 20, "_class" : "com.test.mongodb.entity.Employee" }


4. We can query data with a condition as following.

> db.employee.find({name:'Ram'})
{ "_id" : 1, "name" : "Ram", "age" : 20, "_class" : "com.test.mongodb.entity.Employee" }



Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us