Mongoose is MongoDB driver module which provide REST features to build faster MongoDB apps with Nodejs.
MongoDB
MongoDB is a NoSQL database which store data as JSON document and collections. In JavaScript applications we can utilize the mongoose driver to perform Mongo operations. First up all we need to install mongoose to your project and then import the module.
npm install mongoose
Saving the document
mongoose uses the modal class to perform REST operations. If you are not familiar have a look at the mongoose modal post given below
Tag.create({
tagName: tagNa}, function(error, stag) {
if (error) return handleError(error)
console.log(new tag saved : ${stag.tagName}
);
})
The Tag is the Modal and the create method is used to save the document to database and it also use a callback function to return the result.
We can also use an asynchronous method find documents in Mongoose as follows
const tag=new Tag({tagName:'SQL'}) await tag.save()
That’s it. Following mongoose posts deserve your attention
- How to interact with input in Reactjs - How to handle state and event of input element in React apps
- How to populate multiple MongoDB objects on the same path in express-node - How to populate multiple objects in MongoDB in the same path
- How to populate selected fields in a mongo document path in expressjs - How to populate object in mongo doc at a specific path with specific fields
- How to populate and display nested mongo objectin express-node route - How to populate object in express-MongoDB app
- How to render mongo object in Reactjs - How to render MongoDB object/ObjectId in React/MERN app
- How to render list of mongo objects in React component - How to render list of mongo objects in Reactjs
- How to place custom route links in Reactjs component - How to place custom links to routes/page in Reactjs
- How to filter MongoDB object list in express-node app - How to filter a mongo object list in document in express-node app
- How to fix mongo object Type error in Reactjs - How to fix TypeError/undefined in React - MERN application
- How to create document using mongoose in express-node app - How to save MongoDB document to the collection using mongoose REST operations