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")
}