How to install mongoose with npm and import into NodeJs

Introduction MongoDB and NodeJs are often used together for developing back-ends. MongoDB is a NoSQL database. To connect the database and manage relationships between data, the mongoose is used. It is an Object Data Modeling (ODM) library. It provides schema validation and also helps in managing relationships between data. In this article, we will discuss … Continued

Understanding the mongoose _id field

Introduction MongoDB is one of the most popular NoSQL databases. It stores data in the BSON format. BSON format is an extension of the JSON format that provides more data types. Have a look at the following document. 123456789{     "name" : "Rambo",     "age": 5,     "isAdopted" : false,     … Continued

How to Use Mongoose with a db

Introduction MongoDB is one of the most popular NoSQL databases. It stores data in BSON format (an extension of JSON). It is relatively faster than SQL databases and handles unstructured data very efficiently. MongoDB is often used with NodeJS. For object mapping between MongoDB and NodeJS, a library known as Mongoose is used. Mongoose is … Continued

Fetching Data from MongoDB using get in mongoose

Introduction As we all know, a database is used to store data. But it is not just that. We always don’t have static data. After setting up a database, we may need to perform many operations. We may need to add more data, or we need all the data or some data. We may also … Continued

The mongoose $in Operator

Introduction CRUD operations in mongoose are very important to understand. These operations include data retrieval, insertion, updating, and deletion. Mongoose provides several methods for such operations. All of these methods have a query and a projection part. A query specifies how the document will be filtered. Generally, it is an object. Have a look at … Continued

How to Use Mongoose Validators

Introduction When working with mongoose, one of the very first steps is to define the schema. The schema defines the structure of documents and default values of the fields. But this is not enough. We need to define validations too. Without validations, any type of data can be inserted in the database and this is … Continued

How to Use Mongoose Custom Validators

Introduction Validating a schema is always recommended. Validations make the database better structured and avoid the insertion of bad data into it. Mongoose provides several built-in validators such as required, minlength, maxlength, min, and max. These built-in validators are very useful and simple to configure. But validations in mongoose are not limited only to built-in … Continued

How to use Mongoose to Update in Bulk

Introduction Of all the four CRUD operations, the update is the one that needs to be done very carefully, especially when there are bulk of documents to be updated. One single mistake can lead to serious trouble. Imagine, there are hundreds of documents in a collection and we try to update the bulk of documents … Continued

How to Use Mongoose Lean

Introduction Mongoose provides many methods for retrieving documents from a Mongoose collection. These methods include find(), findOne(), findById(), etc. The find() method is the most popular and widely used. It returns multiple documents based on the condition specified. But when there is a huge amount of documents in a collection, the find() method lacks performance. … Continued

How to Use Mongoose Populate

Introduction In real-time, there are many collections in a MongoDB database. While working with an application, we may need to link these collections. It is a bit complex task, but mongoose provides the populate() method that helps us with this. In this article, we will discuss how to use mongoose populate. Let’s jump in! Schemas … Continued

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.