![]() |
NPM, which stands for Node Package Manager, is the default package manager of Node.js. As the default package manager, NPM is used to manage all the packages and the modules in Node.js. We can do so using the command line client npm. In this article, we are going to learn about the Mongoose package provided by npm. PrerequisitesWhat is Mongoose?The Mongoose module is one of Node.js’s most potent external modules. To transfer the code and its representation from MongoDB to the Node.js server, Mongoose is a MongoDB ODM (Object Database Modelling) tool. Installation of Mongoose module:Step 1: You can install this package by using this command. npm install mongoose Step 2: After installing the mongoose module, you can check your mongoose version in the command prompt using the command. npm version mongoose Step 3: After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command. node index.js Following is the dataset, We are using in the following examples. Project Structure: Example: Finding and Updating DocumentIn this example, I am updating the company to Google the document with _id 2.
node index.js Console Output After the Query: ![]() Document after the query was run Example: Updating DocumentIn this example, we are updating the gender to female in the third document.
Step to Run Application: Run the application using the following command from the root directory of the project: node index.js Before the Query: ![]() Document before the query was run After the Query: ![]() Document after the query was run Example: Deleting DocumentIn this example, we are trying to delete a document with last_name=Bourgeois. As there is a document that matches the condition, it will be deleted.
Step to Run Application: Run the application using the following command from the root directory of the project: node index.js Console Output: ![]() Number of deleted documents |
Reffered: https://www.geeksforgeeks.org
Web Technologies |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |