How to Connect Node to a MongoDB Database ?
To connect node to a MongoDB database we can use mongoose library from npm, It is an Object Data Modeling Library that provides predefined methods for database connection, creating schema and models....
read more
MongoDB – Create Database using Mongo Shell
A MongoDB Database is the container for all the collections, where the Collection is a bunch of MongoDB documents similar to tables in RDBMS and the Document is made up of fields similar to a tuple in RDBMS, but it has a dynamic schema here....
read more
Mongoose save() Function
The `save()` function in Mongoose serves the purpose of persisting a document in the MongoDB database. By invoking this function, you can add new documents to the database or update existing ones. It facilitates the process of storing the document, along with its associated data, in the designated MongoDB collection, making the information persistent and accessible for future retrieval and queries....
read more
Mongoose | findByIdAndDelete() Function
The findByIdAndDelete() function is used to find a matching document, removes it, and passing the found document (if any) to the callback....
read more
Mongoose | deleteOne() Function
The deleteOne() function is used to delete the first document that matches the conditions from the collection. It behaves like the remove() function but deletes at most one document regardless of the single option. Installation of mongoose module:...
read more
Mongoose | findOneAndDelete() Function
The findOneAndDelete() function is used to find a matching document, remove it, and passes the found document (if any) to the callback....
read more
Mongoose | updateMany() Function
The updateMany() function is same as update(), except MongoDB will update all documents that match the filter. It is used when the user wants to update all documents according to the condition....
read more
Mongoose | exists() Function
The exists() function returns true if at least one document exists in the database that matches the given filter, and false otherwise....
read more
Mongoose | findOneAndUpdate() Function
The findOneAndUpdate() function is used to find a matching document and update it according to the update arg, passing any options, and returns the found document (if any) to the callback....
read more
Mongoose | countDocuments() Function
The countDocuments() function is used to count the number of documents that match the filter in a database collection....
read more
How to check if a string is valid MongoDB ObjectId in Node.js ?
MongoDB ObjectId: MongoDB creates a unique 12 bytes ID for every object using the timestamp of respective Object creation.This ObjectId can be used to uniquely target a specific object in the database....
read more
Mongoose | update() Function
The update() function is used to update one document in the database without returning it....
read more