From the course: MongoDB Node.js Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Inserting a document in Node.js applications

Inserting a document in Node.js applications

From the course: MongoDB Node.js Developer Associate Cert Prep

Inserting a document in Node.js applications

- Hello, in this video, you'll learn how to use the insertOne and insertMany methods to create single documents and multiple documents in MongoDB with a Node.js application. We use the insertOne method to insert a single document into a MongoDB collection. Let's look at this in action. First, we'll create a new document in the accounts collection of the bank database. We started by creating a JavaScript object called sampleAccount that models the document format that we're going to insert. The document has a number of fields that store information about the account, such as the account_holder, account_id, account_type, and balance. Notice that we have not included an _id field. MongoDB documents are assigned an _id field that uniquely identifies each document in a collection after the document is inserted. We can think of the _id field as being equivalent to a primary key. If we don't provide a value for the _id field,…

Contents