#Use mongoose without nestjs/mongoose

5 messages · Page 1 of 1 (latest)

warm bobcat
#

Can you provide an analysis of the advantages and disadvantages of using "nestjs/mongoose" instead of opting for vanilla Mongoose? I find it confusing to use the NestJS package due to the differences in typing compared to the official Mongoose documentation. The official documentation clearly explains how to type the model and static methods, but this is not as well-documented in nestjs/mongoose. Additionally, I struggle to find resources, tutorials, and a supportive community for the package. Could you provide further insights and best practices for using nestjs/mongoose? Specifically, I would like to know how to properly handle typing and the most confusing aspect: correctly serializing the responses. I am starting to question whether returning the entire object with some decorators from class-transformer is the best approach. Most tutorials with TypeORM utilize this method, but I believe that constructing a response DTO and applying the plainToInstance method may be a better approach for Mongoose.

Here you can see the proper typing with interfaces which is advised in the mongoose's documentation: https://mongoosejs.com/docs/typescript/statics-and-methods.html

scarlet umbra
warm bobcat
#

@scarlet umbra Can you give me some examples what is the difference between nestjs/mongoose and nestjs/typegoose. At first sight they look the same

scarlet umbra
#

@warm bobcat - Look again and more closely. The Typegoose documentation is filled with differences or rather, a ton more features and the documentation alone is a huge difference (it's much more encompassing). And yes, they work similarly, but definitely not the same. The Typegoose docs also answer your question, "why not just use Mongoose". Having to write out interfaces AND schemas is a waste of good dev time. 🙂

warm bobcat
#

@scarlet umbra Okay, but when using only nestjs/mongoose do you advise decorating the properties with class-transformer directly in the schema or creating separate DTO