Setup MongoDB With Nest.js | Simple + Scaleable

Поділитися
Вставка
  • Опубліковано 25 лют 2021
  • Github: github.com/mguay22/nestjs-mongo
    Docs: docs.nestjs.com/techniques/mo...
    Get my highly-rated Udemy courses at a discount here: michaelguay.dev/udemy/
  • Наука та технологія

КОМЕНТАРІ • 50

  • @mguay
    @mguay  5 місяців тому

    Get my highly-rated Udemy courses at a discount here: michaelguay.dev/udemy/

  • @nearmint8350
    @nearmint8350 2 роки тому

    Amazing Michael! Good job!

  • @TheBrownBox
    @TheBrownBox 2 роки тому

    Hi Michael, A very straight forward tutorial!
    Thank you very much!

  • @pecheritsa_alex
    @pecheritsa_alex 9 місяців тому

    Amazing and so clean and helpful video! Thank you so much!🙏

  • @suhasa5542
    @suhasa5542 2 роки тому

    Thanks, just what I needed, subscribed!

  • @OleksandrDanylchenko2k
    @OleksandrDanylchenko2k 3 роки тому

    Thanks for good example of extensible repo

  • @dimahrist7573
    @dimahrist7573 2 роки тому

    You helped me a lot! Thanks)

  • @bbedyukh
    @bbedyukh Рік тому

    Thank you!

  • @Monsterkosh
    @Monsterkosh 2 роки тому +1

    Whats the vscode theme you are using ? Thanks (L

  • @akashgautam6565
    @akashgautam6565 Рік тому +1

    I was following along but after you wrote the code for module and repository suddenly the code for service and controller is already there. Would have been better if we could follow along through that as well.

  • @moosegoose1282
    @moosegoose1282 Рік тому

    hey bro do you know how to type the projection? this is as far as i got
    async find(
    entityFilterQuery: FilterQuery,
    projection?: Partial<
    Record
    >,
    ): Promise {}
    the extends part isn't working :/

  • @jeromenolasco8921
    @jeromenolasco8921 3 роки тому +1

    Hi! New subscriber here! I'm new to Node and Typescript and NestJS and MongoDB. Loving your NestJS related vids!
    Amazing to find very good tutorial like this with application of some best practices such as creating a Repository Layer.
    Hope you could provide or help on how to make a generic/abstract class for Repository?
    Also, if you could provide tutorial on Atomic Transaction Management in MongoDB/Mongoose in NestJS way.

    • @mguay
      @mguay  3 роки тому +1

      Thank you for the kind works Jerome. Sure, happy to make some videos on those topics and I think that is a great idea. Keep an eye out for that later this month.

  • @eddyv524
    @eddyv524 Рік тому

    HI Michael, thanks for the video. There is one question i have: In the route handlers in the controller file, the return type is a Promise. Which part of the code waits for the Promise to get resolved? You can't really return a Promise to a client like postman.. Just trying to understand how this really works.

    • @mguay
      @mguay  Рік тому +1

      Great question, if we look at the Nest.js source code I would imagine it's calling await on our route (or maybe it's Express under the hood?) - this is a good exercise

  • @shubhampatil5935
    @shubhampatil5935 7 місяців тому

    From where did you learn NestJs?

  • @dmytrodomaretskyi5757
    @dmytrodomaretskyi5757 2 роки тому

    Great video. Thx

  • @paneurhythmie
    @paneurhythmie Рік тому

    Thank you for the greate video. Could you please complete the delete user endpoint?

  • @LukeSamkharadze
    @LukeSamkharadze 2 роки тому

    Can we use this user schema in other modules or do we have to describe schemas in shared modules?

    • @mguay
      @mguay  2 роки тому +1

      You can certainly use it in other modules. You really only need to initialize it one module. If you use it in multiple places, it may be cleaner to instantiate it in a shared module like you suggest.

  • @DazDotOne
    @DazDotOne 2 роки тому +2

    Hi Michael, Thanks for the great content. Really helping me with rapidly learning some NestJS.
    Can I just ask though, is there any difference between what you are calling a repository and what NestJS calls a service?
    I get that the repository is named after the pattern but is it simply a case of (more sensible on your part) naming conventions?
    The reason I ask is that one of the main selling points of Nest for me is to be able to standardise some of the coding practices amongst my team.
    As such I'm hoping to take advantage of the generators provided by Nest. However, when you generate a resource it automatically creates a service rather than a repository.
    Also, I seem to be getting a typescript error using `FilterQuery` within my repository:
    `Argument of type 'FilterQuery' is not assignable to parameter of type 'FilterQuery'.`
    Have you ever seen that before?

    • @mguay
      @mguay  2 роки тому +1

      Hey, Daniel thanks for watching. For me, the difference between a repository and a service is their responsibilities.
      The repository is the only class that has a handle to the underlying DB implementation so it can perform CRUD operations on it. Importantly, it abstracts away the underlying implementation. If we swapped MongoDB out for MySQL in the repository, the users of the repository wouldn't know the difference because they simply call the public methods on it.
      A service is a more generic term that can encompass many business operations.
      And I believe you need to pass the UserDocument to the FilterQuery as Mongo expects the type to be a schema.

    • @DazDotOne
      @DazDotOne 2 роки тому

      @@mguay Did you remove my response or am I going crazy?

    • @mguay
      @mguay  2 роки тому

      @@DazDotOne I got a notifiation for it, but when I looked I didn't see it. I didn't remove it, promise!

    •  2 роки тому

      @@mguay Your approach is very similar of what I used to do in symfony. Especially when you talk (in the video) about create a generic crud and extends it to every others repositories like "userRepository extends abstractRepository". I'm just learning nestJs but I guess it's what you meant. Great video btw :)

  • @luismiguelardilarendon3542
    @luismiguelardilarendon3542 2 роки тому +2

    Someone also have an error on controller class? the userModle its define to contain a Model but the method return a userFilterQuery with user instance.

    • @jamols09
      @jamols09 2 роки тому

      same I get error

    • @olok95ify
      @olok95ify 2 роки тому

      You need to pass the UserDocument instead of User like FilterQuery

    • @qyzi
      @qyzi 2 роки тому

      @@olok95ify thanks !

  • @amitmondal7427
    @amitmondal7427 3 роки тому +1

    This tutorial is really good.
    Can you please make some videos for Nest.js and web sockets?
    Thank you.

    • @mguay
      @mguay  3 роки тому +1

      Great idea. That will be my next video. Thanks!

    • @amitmondal7427
      @amitmondal7427 3 роки тому

      @@mguay Thank you.

  • @marcelofernandez6561
    @marcelofernandez6561 2 роки тому

    Que Guay Miguel

  • @blacktipe9922
    @blacktipe9922 2 роки тому

    when I do a post request with the json data, its returning
    {
    "statusCode": 404,
    "message": "Cannot POST /",
    "error": "Not Found"
    }

    • @mguay
      @mguay  2 роки тому

      Is your server running? Do you see any errors?

    • @blacktipe9922
      @blacktipe9922 2 роки тому

      @@mguay server running, yeah. Error above (postman)

    • @mguay
      @mguay  2 роки тому

      It sounds like an issue with the controller. Did you register it in the controllers array in the module? And do the decorators match the request you are sending? You should be able to see it in the Nest logs when you start the app.. something like this:
      Mapped {/users/search, GET} route

    • @blacktipe9922
      @blacktipe9922 2 роки тому

      @@mguay uhm I only installed it and tried to run it, so i guess no

    • @sanatjee8420
      @sanatjee8420 2 роки тому

      Wire UserModule in app.module.ts in import's array and import it at the top in the same file from users.module

  • @buka.a
    @buka.a 2 роки тому

    A bit similar to how things are done in ASP Dotnet Core

  • @jamols09
    @jamols09 2 роки тому +1

    I really don't get the purpose of adding forFeature and defining a *{ name: **User.name**, schema: UserSchema }* why not just *{ schema: UserSchema }* ?

    • @mguay
      @mguay  2 роки тому +3

      Hi, the MongooseModule requires that you provide a name for the Model being defined:
      export declare type ModelDefinition = {
      name: string;
      schema: any;
      collection?: string;
      discriminators?: DiscriminatorOptions[];
      };

    • @madd-tv
      @madd-tv Рік тому

      because Nest.js needs to identify each model by some kind of token (and model name is part of the token I guess). You can later inject model with this identifier in other providers.

  • @hammadumar4878
    @hammadumar4878 Рік тому

    Sir, Please make a video on gRPC with Nest.js.

    • @mguay
      @mguay  Рік тому

      Great idea!

  • @itchaneljt7979
    @itchaneljt7979 2 роки тому +1

    Hi Michael, I have a code error in usersFilterQuery: No overload matches this call.
    Overload 1 of 3, '(callback?: Callback): Query', gave the following error.
    Argument of type 'FilterQuery' is not assignable to parameter of type 'Callback'.
    Type 'FilterQuery' provides no match for the signature '(error: NativeError, result: (User & Document & { _id: any; })[]): void'.
    Overload 2 of 3, '(filter: FilterQuery, callback?: Callback): Query', gave the following error.
    Argument of type 'FilterQuery' is not assignable to parameter of type 'FilterQuery'.
    Overload 3 of 3, '(filter: FilterQuery, projection?: any, options?: QueryOptions, callback?: Callback): Query', gave the following error.
    Argument of type 'FilterQuery' is not assignable to parameter of type 'FilterQuery'.

  • @ezevalentine7610
    @ezevalentine7610 3 роки тому +1

    Looks more complicated here than in express

    • @jamols09
      @jamols09 2 роки тому

      true nestjs is pretty tough to learn

  • @miguelangelchamorrofuentes9248
    @miguelangelchamorrofuentes9248 3 роки тому

    very difuse the visual content

  • @vithusas4024
    @vithusas4024 3 роки тому

    Hello, Can you do a video setup mysql db? But can you use Nestjs without TypeOrm ? I really want to know how to setup a program using sql statement instead of type orm ? I've seen so many videos with TypeOrm .
    Thanks