
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 push value with for loop in MongoDB?
To push value, use save() along with for loop. Let us create a collection with documents −
> for(var v=1; v<7; v++) { ... db.demo739.save({Name:"Chris",SubjectName:"MongoDB"}); ... } WriteResult({ "nInserted" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo739.find();
This will produce the following output −
{ "_id" : ObjectId("5ead6e7857bb72a10bcf0666"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0667"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0668"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0669"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf066a"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf066b"), "Name" : "Chris", "SubjectName" : "MongoDB" }
- Related Questions & Answers
- Work with $push in MongoDB
- How to push an array in MongoDB?
- Updating an array with $push in MongoDB
- Push query results into variable with MongoDB?
- MongoDB $push in nested array?
- How to loop through collections with a cursor in MongoDB?
- How do I $set and $push in single update with MongoDB?
- How to push an element into array in MongoDB?
- How to update document with marks value in MongoDB for student David
- How can I write in order with for loop or while loop?
- How to convert a Python for loop to while loop?
- Python - How to convert this while loop to for loop?
- How do I push elements to an existing array in MongoDB?
- Not able to push all elements of a stack into another stack using for loop in JavaScript?
- Implement MongoDB $push in embedded document array?
Advertisements