---
title: Mongoose vs Typegoose in NestJS - elpassion.com
description: Choosing MongoDB database in your system, you’ll probably also use an ODM library. See the main Moongoose vs Typegoose differences, especially when you
image: https://www.elpassion.com/hubfs/moongoose-vs-typegoose-in-nestjs.jpg
---

[Back to blog ](https://www.elpassion.com/blog?hsLang=en)

 27 March 2023 (updated: 19 December 2024)

# Mongoose vs Typegoose in NestJS

[![](https://www.elpassion.com/hubfs/PawelSierant_author.png) ![](https://www.elpassion.com/hubfs/PawelSierant_author.png) ](https://www.elpassion.com/blog/author/paweł-sierant) [ by Paweł Sierant 

](https://www.elpassion.com/blog/author/paweł-sierant)

- [ Development ](https://www.elpassion.com/blog/tag/development)

Chapters

![](https://www.elpassion.com/hubfs/moongoose-vs-typegoose-in-nestjs.jpg) ![](https://www.elpassion.com/hubfs/moongoose-vs-typegoose-in-nestjs.jpg)

 Show contents  Hide contents

After you choose the MongoDB database in your system, you’ll probably also use an ODM library. The most popular is Mongoose or a library built on top of it - Typegoose. In this article, we’ll cover their main differences when working specifically with the NestJS framework.

You probably already know that Typegoose is essentially a way to use Mongoose with TypeScript and that would be your criteria when choosing the library. But it’s a bit more to this when working with the NestJS framework because there is a Mongoose wrapper created by NestJS authors - @nestjs/mongoose and when You look at the syntax - it seems almost identical to Typegoose.

Let’s break down the differences between them so it’s easier to decide what approach you should choose in your project - using @nestjs/mongoose package or Typegoose. When integrating MongoDB with a NestJS application, you’ll find examples and code snippets demonstrating how to set up a NestJS application to work with MongoDB using TypeScript and packages like Typegoose.

## Main differences

### Connection and model injection with MongoDB database

@nestjs/mongoose is a library dedicated to the Nest framework so it comes with full support of its DI workflow. On the other hand, Typegoose can be used in any other NodeJS project so you will have to either integrate it with Nest on your own or use community packages.

### Schema definition

Although both packages allow defining schemas using similar decorators, their interfaces vary and Typegoose provides more options than the Nest wrapper. For example - `@Schema()` decorator takes only Mongoose’s defined schema options, whereas `@modelOptions()` in addition to this offers access to an existing connection and some custom Typegoose configuration options.

With `@nestjs/mongoose`, if you want to manually modify the schema definition based on the metadata, you can use the `DefinitionsFactory` class. This approach can be useful when it’s difficult to represent everything using decorators.

### Class methods

Both packages allow defining instances and static methods. Here are examples on how we can define class methods in both packages:

As you can see, we have to create additional interfaces when using mongoose, Typegoose however allows us to get type information from classes. The definitions are also more natural as they are contained within a class like regular methods. With the Nest package, you have to use the `statics` and `methods` properties outside of the class, which slightly reduces readability and becomes a less natural approach when it comes to using classes.

### Hooks

Both packages support hooks. In @nestjs/mongoose you can use them in the factory method of module imports. Typegoose offers support with @pre() and @post() decorators.

### Custom query methods

You can add custom queries in both packages, but you will probably encounter type issues in Mongoose. The difference between a query method and a static function on the model is that the function would not be chainable

### Virtuals

Virtual properties can be created in Typegoose using ES6 get & set functions, whereas with the Nest package you have to use the `virtual` property outside of the class, which similarly to class methods, feels less natural to work with.

## Which one should you choose?

Although Mongoose already can infer types from schema definition and its Nest wrapper has cool features you’ll still benefit more when using Typegoose. It also has better documentation and community support. The question is - do you have the time and resources to integrate Typegoose into your Nest project? If so, I’d personally give it a chance.

### Check out also

- [Making Your Project's Setup Easier and Cheaper with Generic Templates and Monorepos](https://www.elpassion.com/blog/making-project-setup-cheaper-with-templates-and-monorepos?hsLang=en) — The big guys are not wrong when they're using monorepos for their projects. Monorepos along with a generic template can make your project's setup faster (and cheaper).

[Share on Twitter ](http://twitter.com/share?url=https://www.elpassion.com/blog/mongoose-vs-typegoose-in-nestjs) [Share on LinkedIn ](https://www.linkedin.com/shareArticle?mini=true&url=https://www.elpassion.com/blog/mongoose-vs-typegoose-in-nestjs) [Share on Facebook ](http://www.facebook.com/sharer.php?u=https://www.elpassion.com/blog/mongoose-vs-typegoose-in-nestjs)

[![](https://www.elpassion.com/hubfs/PawelSierant_author.png) ![](https://www.elpassion.com/hubfs/PawelSierant_author.png) ](https://www.elpassion.com/blog/author/paweł-sierant)

[ Paweł Sierant 

](https://www.elpassion.com/blog/author/paweł-sierant)

 Backend Developer

<https://www.linkedin.com/in/paweł-sierant-325471219/>

## You may also like

[![](https://4937048.fs1.hubspotusercontent-na1.net/hubfs/4937048/BLOG%20IMAGES/refactoring-legacy-code.webp) ![](https://www.elpassion.com/hubfs/BLOG%20IMAGES/refactoring-legacy-code.webp) ](https://www.elpassion.com/blog/the-product-health-check-how-to-find-performance-bottlenecks-before-they-cost-you-users?hsLang=en)

- [ Development ](https://www.elpassion.com/blog/tag/development)

### [The Product Health Check: How to Find Performance Bottlenecks Before They Cost You Users](https://www.elpassion.com/blog/the-product-health-check-how-to-find-performance-bottlenecks-before-they-cost-you-users?hsLang=en)

 5 July 2026 • EL Passion

[![](https://4937048.fs1.hubspotusercontent-na1.net/hubfs/4937048/BLOG%20IMAGES/remote_team.jpg) ![](https://www.elpassion.com/hubfs/BLOG%20IMAGES/remote_team.jpg) ](https://www.elpassion.com/blog/staff-augmentation-vs.-managed-teams-which-model-saves-you-more-on-long-term-overhead?hsLang=en)

- [ Development ](https://www.elpassion.com/blog/tag/development)
- [ Business ](https://www.elpassion.com/blog/tag/business)

### [Staff Augmentation vs. Managed Teams: Which Model Saves You More on Long-Term Overhead](https://www.elpassion.com/blog/staff-augmentation-vs.-managed-teams-which-model-saves-you-more-on-long-term-overhead?hsLang=en)

 5 July 2026 • EL Passion

[![](https://4937048.fs1.hubspotusercontent-na1.net/hubfs/4937048/BLOG%20IMAGES/refactoring-legacy-code.webp) ![](https://www.elpassion.com/hubfs/BLOG%20IMAGES/refactoring-legacy-code.webp) ](https://www.elpassion.com/blog/legacy-app-refactoring-and-technical-debt?hsLang=en)

- [ Development ](https://www.elpassion.com/blog/tag/development)
- [ Business ](https://www.elpassion.com/blog/tag/business)

### [The Cost of Waiting: How Refactoring Your Legacy App Prevents Massive Technical Debt in 2026](https://www.elpassion.com/blog/legacy-app-refactoring-and-technical-debt?hsLang=en)

 31 May 2026 • EL Passion

Maybe it’s the beginning of a beautiful friendship?

## We’re available for new projects.

[![Contact us](https://no-cache.hubspot.com/cta/default/4937048/d8fa95f1-46dc-4ecf-b1a6-aa709c23404b.png)](https://cta-redirect.hubspot.com/cta/redirect/4937048/d8fa95f1-46dc-4ecf-b1a6-aa709c23404b)

```json
{
  "@context" : "http://schema.org",
  "@type" : "Organization",
  "address" : {
    "@type" : "PostalAddress",
    "addressCountry" : "Poland",
    "addressLocality" : "Warsaw",
    "addressRegion" : "Mazowieckie",
    "postalCode" : "",
    "streetAddress" : "Grzybowska 62 "
  },
  "email" : "projects@elpassion.com",
  "foundingDate" : "2011",
  "foundingLocation" : "Warsaw, Poland",
  "logo" : "https://www.elpassion.com/hubfs/elp_mnt_black.svg",
  "mainEntityOfPage" : {
    "@id" : "https://www.elpassion.com/blog/mongoose-vs-typegoose-in-nestjs",
    "@type" : "WebPage",
    "description" : "Choosing MongoDB database in your system, you’ll probably also use an ODM library. See the main Moongoose vs Typegoose differences, especially when you're working with the NestJS framework."
  },
  "member" : {
    "@type" : "Person",
    "jobTitle" : "CEO",
    "name" : "Anna Elwart",
    "nationality" : "Poland",
    "url" : "https://www.linkedin.com/in/annaelwart/"
  },
  "name" : "El Passion",
  "numberOfEmployees" : "60",
  "sameAs" : [ "https://twitter.com/elpassion", "https://www.facebook.com/elpassion/", "https://www.linkedin.com/company/el-passion", "https://github.com/elpassion", "https://www.behance.net/elpassion", "https://dribbble.com/elpassion" ],
  "url" : "https://www.elpassion.com",
  "vatId" : "PL5213644497"
}
```

```json
{
  "@context" : "http://schema.org",
  "@type" : "WebSite",
  "url" : "https://www.elpassion.com/"
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : [ {
    "@type" : "Person",
    "name" : "Paweł Sierant",
    "url" : "https://www.elpassion.com/blog/author/paweł-sierant"
  }, {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : "150",
      "url" : "https://26048673.fs1.hubspotusercontent-eu1.net/hubfs/26048673/EL-Passion-Logo-400x150.svg",
      "width" : "400"
    },
    "name" : "EL Passion",
    "url" : "https://www.elpassion.com"
  } ],
  "dateModified" : "2024-12-19",
  "datePublished" : "2023-03-27",
  "headline" : "Mongoose vs Typegoose in NestJS - elpassion.com",
  "image" : "https://www.elpassion.com/hubfs/moongoose-vs-typegoose-in-nestjs.jpg",
  "inLanguage" : "en",
  "mainEntityOfPage" : {
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : "150",
      "url" : "https://26048673.fs1.hubspotusercontent-eu1.net/hubfs/26048673/EL-Passion-Logo-400x150.svg",
      "width" : "400"
    },
    "name" : "EL Passion",
    "url" : "https://www.elpassion.com"
  },
  "url" : "https://www.elpassion.com/blog/mongoose-vs-typegoose-in-nestjs"
}
```