Contents of page >
- Display documents of collection in formatted manner.
Display documents of collection in formatted manner
(Pretty print the documents).
(Pretty print the documents).
First, Let's create new collection and insert document in it >
> db.employee.insert({_id : 1, firstName:"ankit"})
> db.employee.insert({_id : 2, firstName:"ankit", salary : 1000 })
> db.employee.insert({_id : 3, firstName:"sam", salary : 2000 })
> db.employee.insert({_id : 4, firstName:"neh", salary : 3000 })
|
First line above will create table (or collection) (if table already exists it will insert documents in it).
FIND Example > Query all document of collection using find().pretty() method>
> db.employee.find().pretty()
|
Output>
{
"_id" : 1,
"firstName" : "ankit"
}
{
"_id" : 2,
"firstName" : "ankit",
"salary" : 1000
}
{
"_id" : 3,
"firstName" : "sam",
"salary" : 2000
}
{
"_id" : 4,
"firstName" : "neh",
"salary" : 3000
}
|
SUMMARY>
So in this mongoDB tutorial we learned how to Pretty print the documents - Display documents of collection in formatted manner in mongoDB in mongoDB.
> db.employee.find().pretty()
|
Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>
What is MongoDB - A quick introduction to database
Labels:
MongoDB
Query MongoDB