Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a new object and get its saved object in MongoDB?
For this, use save() in MongoDB. Following is the syntax −
var anyVaribaleName=yourValue db.anyCollectionName.save(yourVariableName); yourVariableName;
Let us first create an object for our example −
> var studentDetails={"StudentName":"Chris","ListOfMarks":[56,78,89],"ListOfSubject":["MySQL","Java","MongoDB"]};
Let us save the above created object “studentDetails” −
> db.demo40.save(studentDetails);
WriteResult({ "nInserted" : 1 })
Let us display the value −
> studentDetails;
This will produce the following output −
{
"StudentName" : "Chris",
"ListOfMarks" : [
56,
78,
89
],
"ListOfSubject" : [
"MySQL",
"Java",
"MongoDB"
],
"_id" : ObjectId("5e177757cfb11e5c34d898e2")
}Advertisements