Node.js MongoDB Insert Record29 Aug 2024 | 2 min read The insertOne method is used to insert record in MongoDB's collection. The first argument of the insertOne method is an object which contains the name and value of each field in the record you want to insert. Example (Insert Single record) Insert a record in "employees" collection. Create a js file named "insert.js", having the following code: Open the command terminal and run the following command: ![]() Now a record is inserted in the collection. Insert Multiple RecordsYou can insert multiple records in a collection by using insert() method. The insert() method uses array of objects which contain the data you want to insert. Example Insert multiple records in the collection named "employees". Create a js file name insertall.js, having the following code: Open the command terminal and run the following command: ![]() You can see here 4 records are inserted. Next TopicNode.js MongoDB Select |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

