How to limit the number of documents in a MongoDB request in Node.js ?
Say you are working on a quiz API, with which anybody on the web can fetch random questions based on the defined category. You are done with your API and it has passed all test parameters, now for sake of users you want to add a feature that will let users decide how many questions they want to address and your API will provide them with that amount of questions. Here, comes the helpful mongo feature limit....
read more
Mongoose Schema.prototype.pre() API
The Mongoose Schema API pre() method is used to add a pre-hook to the mongoose Schema methods and can be used to perform pre Schema method operations....
read more
How to get Distinct Documents from MongoDB using Node.js ?
MongoDB is a cross-platform, document-oriented database that works on the concept of collections and documents. It stores data in the form of key-value pairs and is a NoSQL database program. The term NoSQL means non-relational....
read more
How to add unique constraint in collection of MongoDB using Node.js?
Mongoose module is one of the most powerful external modules of the node.js.Mongoose is a MongoDB ODM i.e (Object database Modelling) that used to translate the code and its representation from MongoDB to the Node.js server. Mongoose module provides several functions in order to manipulate the documents of the collection of the MongoDB database....
read more
Aggregate Queries
MongoDB is a NoSQL document model database, and it is mainly used in Big Data analysis like election poll results, growth of an industry in the past few years, etc., For doing huge computations, in MongoDB, we use aggregation....
read more
How to wait for MongoDB connection to be made before creating HTTP server in Node.js?
Connecting your server to is a database a very crucial task in back-end development as the database is the location where the user-provided data will be stored until further action is taken....
read more
How to get information of all databases present in MongoDB using Node.js ?
MongoDB, the most popular NoSQL database, we can count the number of documents in MongoDB Collection using the MongoDB collection.countDocuments() function. The mongodb module is used for connecting the MongoDB database as well as used for manipulating the collections and databases in MongoDB....
read more
How to push data in a MongoDB document ?
The insertOne() and insertMany() are the two methods of the MongoDB module in node.js that are used to push the documents in the collections of the MongoDB database. The insertOne() method inserts one data at a time into the collection and insertMany() method inserts multiple data into the collection of the MongoDB database. In this article, we will discuss how to push data in MongoDB collection using MongoDB module methods....
read more
Mongoose Document Model.remove() API
The Model.remove() method of the Mongoose API is used to remove all the documents present in the collection in one go. It will be called on a Collection model which is already defined and present in the database....
read more
RESTfull routes on Node.js and MongoDB
REST stands for representational state transfer which basically provides a way of mapping HTTP verbs such as (GET, POST, PUT, DELETE) with CRUD actions such as (CREATE, READ, UPDATE, DELETE). Whenever we click on a link on the webpage we are basically making a state transfer from one page to another. For example, when we click for the homepage of the blog website we want to get all the blogs that are stored on the server’s database which is basically a mapping of HTTP GET request with the READ request of database....
read more
How to create new Mongodb database using Node.js ?
mongodb module: This Module is used to performing CRUD(Create Read Update Read) Operations in MongoDb using Node.js. We cannot make a database only. We have to make a new Collection to see the database. The connect() method is used for connecting the MongoDb server with the Node.js project....
read more
Mongoose Populate Virtuals
The mongoose populate method can be used to fetch referenced documents and populate them in the query result. Virtuals are properties that are not persisted in the database but are computed on the fly by the model. To populate a virtual property, you can use the populate() method with an options object that has a path property that specifies the name of the virtual property to populate. The path property should be set to the name of the virtual property prefixed with an underscore (_)....
read more