How to get a saved object in MongoDB?


Let us first create a variable. Following is the query −

> var studentDetails={"StudentFirstName":"Chris","StudentLastName":"Brown","StudentAge":24};

Following is the query to save records using save() −

> db.demo45.save(studentDetails);
WriteResult({ "nInserted" : 1 })

Display all documents from a collection with the help of find() method −

> studentDetails;

This will produce the following output −

{
   "StudentFirstName" : "Chris",
   "StudentLastName" : "Brown",
   "StudentAge" : 24,
   "_id" : ObjectId("5e25dab4cfb11e5c34d898ec")
}

Updated on: 03-Apr-2020

192 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements