DEV Community

loading...

Discussion on: Simple example Api Rest with NestJS 7.x and Mongoose 😻

Collapse
lowpolybrain profile image
Ilia Andrienko

Yuk! So we have to define a several schema, a several DTOs and a couple interfaces (separately) for each model?
This is sorta ugly :/

Collapse
yannyinnn profile image
Yann • Edited

Same feeling, the title is "Simple example Api Rest " but the implementation feels pretty complex and repetitive; and the nest documentation is not so clear either.

Is this the Nest way to use mongoose ? Is there simpler alternatives ?

Things seems much simpler with Typeorm than with mongoose, but Typeorm says that it has only a "basic support of mongodb"

Collapse
tony133 profile image
Tony Author

Hi Yann,

Everyone can use the methods and implementation they want, you are free to implement them however you like, the choice is yours. Then for the following questions you ask:

Is this the Nest way to use mongoose?
The implementation for using mongoose with Nest is this, I know maybe mongoose is a bit complex to understand.

Is there simpler alternatives ?
an alternative to mongoose?

Thread Thread
yannyinnn profile image
Yann

Actually your examples are okay, i was just not used to Nest so some stuff seemed redundant at first glance, but it is not.

  • Mongoose schema is dedicated to database and might have nested properties, ref to other collections etc

  • CreateUserDto can be different from schema for various reasons

  • You created UpdateUserDto from CreateUserDto to avoid dupplicating code

This makes sense now

Thread Thread
tony133 profile image
Tony Author

Hi Yann, don't worry, sometimes it can happen that you don't understand the code right away and you need some time to understand I've been through it too. Then in software development there will always be difficulties and understanding the code as it is written and why it was written that way.
When I first used Nest, I understood it in a flash, as if I had used it before, but I think it's because I know Angular from the first version and some things are very familiar to me.

However, if you have any doubts, write me without problems.

P.s. If you are having difficulty with Nest you can also use the Discord channel for support

Collapse
tony133 profile image
Tony Author

If you find other ways of implementation you are free to implement them as you like, the choice is yours.