
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
Set Variable Value in MongoDB Save Method
Use db.yourCollectionName.save(yourVariableName) to set variable value, wherein “yourVariableName” is your variable.
Let us see an example and create a variable −
> var Info={"Name":"David", ... "CountryName":"US", ... "ProjectDetails":[{"ClientName":"David","ProjectName":"Online Banking System"}]}
Following is the query to set the variable value in the save() to save the value in the collection −
> db.demo483.save(Info); WriteResult({ "nInserted" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo483.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e82e0d6b0f3fa88e22790a0"), "Name" : "David", "CountryName" : "US", "ProjectDetails" : [ { "ClientName" : "David", "ProjectName" : "Online Banking System" } ] }
Advertisements