Posts for mongoose

Deven
Deven wrote

How to use Mongoose virtual property

In this article, you are going to learn about how to use mongoose virtual property. In mongoose, you can use the virtual property. This will let you work logically on your project. The main benefit of using the virtual property is that it will not persist the document in the MongoDB database. That means you […]

January 15, 2022 in Code examples
Deven
Deven wrote

Learn How to use Mongoose aggregation

In this article, you are going to learn about Mongoose aggregation. In MongoDB, the aggregation pipeline consists of stages and each stage transforms the document. It is extremely powerful and very handy to use. Mongoose comes with aggregate() function by which you can use MongoDB’s aggregation framework with Mongoose. Basically, it is a thin wrapper […]

October 16, 2021 in Code examples
Deven
Deven wrote

How to use findById in Mongoose

Each document inside MongoDB has a unique id associated with it, which helps to identify the document independently. It is similar to primary key defined in MySQL. findById: This method takes Id as input parameter & returns the single matching document. FindById is shortcut of findOne({ _id: id }) example: Once a user hits this […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to get all documents in Mongoose

In this article, You will learn how to get all documents in Mongoose. Let assume, you have a mongoose model User that has all your app’s users information. Now, to get all users list from the mongoose collection you have to call User.find() with an empty object as the first parameter. It will search for […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to use mongoose unique

The term unique is a mongoose default boolean SchemaType. In a mongoose model, a SchemaType says what type a given path should have and what values are valid for that path. It doesn’t actually create MongoDB ObjectIds, it is just a configuration for a path in a schema. The unique option tells Mongoose that each […]

October 14, 2021 in Code examples
Afolayan
Afolayan wrote

Building CRUD API using Restify Framework

A lot of countless options exist for building APIs with JavaScript frameworks these days, and each with their own advantages. This article will focus on explaining the steps to build an API with Create Read Update and Delete (CRUD) functions using the Restify Framework for Node.js. The project we’re going to be building would be […]

February 4, 2020 in Node & Tutorials