how to get records in mongodb


how to get records in mongodb

find() method is use to retrieve all record from mongodb collection and find() methods returns all documents of collection.

Syntax

db.collection_name.find()

Display All Document from Collection

db.stud.find()
/* 1 */
{
    "_id" : ObjectId("56e3f68b24f2c2611ca9c296"),
    "roll" : 101,
    "name" : "Amar Kumar",
    "addr" : "Hyderabad"
}

/* 2 */
{
    "_id" : ObjectId("56e3f68b24f2c2611ca9c297"),
    "roll" : 102,
    "name" : "Vikash Kumar",
    "addr" : "Hyderabad"
}

/* 3 */
{
    "_id" : ObjectId("56e3f68b24f2c2611ca9c298"),
    "roll" : 103,
    "name" : "Vicky Kumar",
    "addr" : "Pune"
}

Display One Document from Collection

db.stud.find({"roll":"101"})
{
    "_id" : ObjectId("56e3f68b24f2c2611ca9c296"),
    "roll" : 101,
    "name" : "Amar Kumar",
    "addr" : "Hyderabad"
}






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229