Multitenancy in NestJS + Mongoose

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 68

  • @sergeyplotnikov4303
    @sergeyplotnikov4303 11 месяцев назад +2

    Thank you very much for this highly valuable content!!! Second approach is awesome.

    • @Computerix
      @Computerix  11 месяцев назад

      Thanks for the feedback!

  • @RishiDeorukhkar
    @RishiDeorukhkar 9 месяцев назад +2

    Amazing tutorial, and great content !! looking forward for more 😄

    • @Computerix
      @Computerix  9 месяцев назад

      Thank you so much!

  • @Viraj-jh6pk
    @Viraj-jh6pk 8 месяцев назад

    this is the most impressive video i have seen on the topic of multitenency with nestjs and mongodb . thank you so much

    • @Computerix
      @Computerix  8 месяцев назад

      Thank you so much!!

  • @ycoda
    @ycoda 11 месяцев назад +1

    Very useful video! Thank you for the knowledge

  • @ShanmugaSabareeshEsaiselvam
    @ShanmugaSabareeshEsaiselvam 8 месяцев назад +4

    This is really a great video. Can you try to implement a authentication module as you said in the video

    • @Computerix
      @Computerix  6 месяцев назад +1

      Here you go : ruclips.net/video/7PSboNf4RuQ/видео.htmlsi=3KUn9tRxLTxJ_x9o

  • @hassanmhassan5500
    @hassanmhassan5500 11 месяцев назад

    Amazing!, wonderful video I really enjoyed it
    keep this good work bro

  • @juhandvan
    @juhandvan 7 месяцев назад

    I find this lesson a bit beyond my understanding (from 26:30) . I hope there will be another lesson in the future that is a little easier to understand.
    Thank so much

    • @Computerix
      @Computerix  6 месяцев назад +1

      I'm gonna make a video covering request scope vs the default scope, hopefully it helps you out!

    • @juhandvan
      @juhandvan 6 месяцев назад

      @@Computerix That sounds interesting.

  • @emirsalihovic6616
    @emirsalihovic6616 9 месяцев назад

    Well done sir.

    • @Computerix
      @Computerix  9 месяцев назад

      Thanks!

    • @emirsalihovic6616
      @emirsalihovic6616 9 месяцев назад

      Can you please cover the topic of dockerizing a nest app and the cloud usage suggestions etc, that would be a great video, thank you!@@Computerix

  • @mohsensareminia2988
    @mohsensareminia2988 8 месяцев назад +1

    Thank you. Why didnt you use nest durable providers?

    • @lev-h2f
      @lev-h2f 8 месяцев назад

      Hello, Please, have you implemented such an architecture that connects several models with mongoose or prisma ?

    • @Computerix
      @Computerix  5 месяцев назад

      @@mohsensareminia2988we could have done that! Good point

  • @omarps6622
    @omarps6622 10 месяцев назад

    Thank you bro , Your content and method of explanation are more than perfect❤
    I also wish if you could share this project with us it would be a great gift for me 🙏

    • @Computerix
      @Computerix  10 месяцев назад

      I'm glad ! The link is in the description : github.com/charbelh3/NestJs-Multi-Tenancy

    • @omarps6622
      @omarps6622 10 месяцев назад

      @@Computerix you are my angel😍

  • @HamoudyMulti
    @HamoudyMulti 8 месяцев назад +1

    thank you for the video! Question, u said that the tenantId comes from the header, but shouldnt it be stored at the users table DB level? does it depend on requirements or it always comes from header of the front end? Thanks in advance

    • @Computerix
      @Computerix  8 месяцев назад +1

      It depends. If you are trying to fetch some data specific to a tenant (so it exists inside the tenant specific Database) for example a list of products being sold by a tenant, you need the frontend to specify the tenantId in the headers (Also it's a best practise to sign each user token with a tenant-specific secret for security purposes) that way, you know where to connect and what data to fetch. However, if a user is trying to login, they send their credentials only. To tell which tenant they belong to, you can store the tenantId inside the users table.
      So in summary, it depends on the requirements, but for most cases, the frontend would need to send the tenandId in the headers.
      Hope this helps :)

    • @HamoudyMulti
      @HamoudyMulti 7 месяцев назад

      @@Computerix Thank you so much for the reply! I just had a meeting with my company and we decided to go with the tenantId in the headers approach. u helped me alot and this video will help me through implementing it in nestjs, making my task easier :D (please dont remove this video lol)
      1 thing we were not sure about is how we can have 1 front end server deal with 2 different domain urls, my company just started implementing custom solutions so we are trying our best, do u know how its done? Thanks alot!

    • @Computerix
      @Computerix  7 месяцев назад

      @HamoudyMulti hmm, can you explain your question more?

    • @HamoudyMulti
      @HamoudyMulti 7 месяцев назад

      @@Computerix I have another question after going through ur video. im currently using a RDS with MS SQL and sequelize ORM. I couldnt apply most of the things in the video, as sequelize doesn't allow u to change database within same connection like in mongoose (in ur videos its the useDB method).
      do u think its a good idea to create all the connections at once when initiliazing the application for all tenants? or initialize the connection on each request for a given tenant? the number of tenants is not that high (3 or 4 max), although im not sure what is the best practice. thanks again for ur great help!

    • @Computerix
      @Computerix  7 месяцев назад

      ​@@HamoudyMulti I haven't used sequelize before, so i'm not very familiar with it. But what you can do, is check if you have an existing connection to a certain tenant DB, if that's the case, use it. If not, create it and use it for the current and future requests for that tenant.
      The key, is managing the connections in a clean way. So make sure to reuse existing connections :))

  • @HellGuyRj
    @HellGuyRj 27 дней назад

    I have a question, for now the connection string is having multiple dbs and useDb is being used to switch the dbs. But, what about the case in which the whole database instance is different, for example 5 dbs on 5 different EC2 machines. How to approach this situation?

  • @pramodpatil2860
    @pramodpatil2860 11 месяцев назад +1

    Excellent tutorials!! Could you please help us to have lookup query on multiple databases? I need to join tenant DB with master and get the result

    • @Computerix
      @Computerix  11 месяцев назад

      Sadly, as per the mongoDb documentation (www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/), lookup only works on collections within the same database.
      However, you can create multiple queries (each query could be on a seperate database) and merge the results yourself.
      To fetch results from the master database :
      1- Simply register the model like we normally do using MongooseSchema.forFeature. (This works, since in app module our default connection is pointing to the master DB)
      2- Inject the model using the normal @InjectModel(). This model will point to a collection in the master DB.
      To fetch results from the tenant specific database, inject the custom tenant model provider like in the video :)
      ..and then manually merge the results

    • @Webtech-nu7hq
      @Webtech-nu7hq Месяц назад

      ruclips.net/video/qR05wWeQ2OI/видео.htmlsi=H40Y7u4bZ12ugdHr

  • @mariusdanyelbuzatu4075
    @mariusdanyelbuzatu4075 7 месяцев назад

    In this case to improve is good to work with redis

  • @shadcnuisnipset
    @shadcnuisnipset 8 месяцев назад

    great tutorial, I really liked it. please can you implement authentication.

    • @Computerix
      @Computerix  7 месяцев назад +1

      I'm planning on doing so sometime this year!
      Just to be clear, authentication handling, specifically in multitenancy, correct?

    • @shadcnuisnipset
      @shadcnuisnipset 7 месяцев назад +1

      @@Computerix yes exactly, registration, login, interaction between the User and Product table for example to know which user created a particular product

  • @j3bb9z
    @j3bb9z 5 месяцев назад

    Hi, thanks for the video. I think it would be useful to make it a durable provider and create dependency tree once per tenant. Did you look at NestJS-CLS (Continuation Local Storage, based on Async Hooks)? I think it's a good altrnative approach, which also works with CQRS module (request scope doesn't).

    • @Computerix
      @Computerix  5 месяцев назад +1

      @@j3bb9z I haven't looked in to it, but the durable provider suggestion is a good one !

  • @abdulrahmanarmashi6954
    @abdulrahmanarmashi6954 8 месяцев назад

    Thank you so much for this great video. I have
    one question: what if we have more then one
    model, should we create a provider for each
    model or is there any way to make the provider generic and accepte any model ?

    • @Computerix
      @Computerix  7 месяцев назад

      Tokens that are injected that represent a provider are unique, so as a first thought I'd say yes, you need to create a provider for each model. I haven't really thought of workarounds or of ways to make something generic work. If you have done that in the past day, let us know!

  • @empowerurjourney
    @empowerurjourney 9 месяцев назад

    Thank you so much for this great content. I have one question: what if we have more then one model, should we create a provider for each model?

    • @Computerix
      @Computerix  9 месяцев назад +1

      Thanks for your comment! Yes that's correct.

  • @lev-h2f
    @lev-h2f 8 месяцев назад

    Thank you for this tutorial, I have a project where I have to use prismaORM to implement multitenancy, can you make another video using prismaORM or provide me with a possible solution. Thanks

    • @Webtech-nu7hq
      @Webtech-nu7hq Месяц назад

      ruclips.net/video/qR05wWeQ2OI/видео.htmlsi=H40Y7u4bZ12ugdHr

  • @thehaughton8936
    @thehaughton8936 9 месяцев назад

    Amazing tutorial, it helped me a lot, but I have a question, you did it multi-tenant in multiple databases, can it also be done but for different collections? Like products_tenant_id in the same data base, or do you know where I can find information about it?
    btw new sub

    • @Computerix
      @Computerix  9 месяцев назад

      Thanks for the feedback! I think it's best if you avoid creating a collection per tenant. Instead go for 1 single database and 1 products collection for all tenants, and create a field named "tenantId" inside the same collection to know which document belongs to which tenant, if you don't want to use the database per tenant approach. (refer to stackoverflow.com/questions/2748825/what-is-the-recommended-approach-towards-multi-tenant-databases-in-mongodb and web.archive.org/web/20140812091703/support.mongohq.com/use-cases/multi-tenant.html)

  • @JoyceWen-py1pb
    @JoyceWen-py1pb 6 месяцев назад

    Hello,
    Your videos have been incredibly helpful to me. I was wondering if we could eventually have the instructional video you mentioned on unified identity verification. I really need it. Thank you, but unfortunately, I can't sponsor you from my region. I apologize.

    • @Computerix
      @Computerix  6 месяцев назад

      I'm glad my videos are helpful!
      I am going to create an authentication video for multitenancy soon, meanwhile feel free to watch this authentication video that I uploaded a week ago : ruclips.net/video/h-68sqxycJY/видео.htmlsi=VeiWno8dL0UA2ike
      It's going to be similar, except we're gonna be using different secret keys for different tenants (these keys would be stored in the database)

    • @JoyceWen-py1pb
      @JoyceWen-py1pb 6 месяцев назад

      @@Computerix Okay, looking forward to your new videos.

  • @ChetanSharma-jy8om
    @ChetanSharma-jy8om 4 месяца назад

    How to solve If i want to read all products from multiple tenants dbs and show them on main website landing page like udemy or other elearning platform.

    • @Computerix
      @Computerix  4 месяца назад +1

      @@ChetanSharma-jy8om If you have such a use case, it's better to keep a copy of the newly created products in your main database (the default mongooseModule that you register), that way you fetch them all from the same DB

    • @ChetanSharma-jy8om
      @ChetanSharma-jy8om 4 месяца назад

      @@ComputerixOne last thing from your side , As you are creating dynamic dbs in mongo db Is there as such limit for them.Because I am using managed mongodb by digital ocean

  • @jean8135
    @jean8135 7 месяцев назад

    The "mustard" database haha

  • @linoypappachan4272
    @linoypappachan4272 11 месяцев назад

    Amazining tutorial, could u pls share source code. Keep it up.

    • @Computerix
      @Computerix  11 месяцев назад +1

      Thank you for the comment!
      Here is the code: github.com/charbelh3/NestJs-Multi-Tenancy

  • @amrhussien4334
    @amrhussien4334 11 месяцев назад

    Thank you, engineer. Great work.
    Hiw can I communicate with you please ❤

    • @Computerix
      @Computerix  11 месяцев назад

      Hello! I was thinking of making a discord community server.. but at a later time. In the meantime, feel free to tell me your concerns here :)

    • @amrhussien4334
      @amrhussien4334 11 месяцев назад

      I have one project I want to discuss it with you via another channel. Appreciate if you can tell me how to reach you. I added my contact here many times but it's deleted
      Thank you

    • @amrhussien4334
      @amrhussien4334 11 месяцев назад

      ​@Computerix I have one project I want to discuss it with you, So please tell how to contact you. I am trying to put my contact here but it always deleted

  • @als5321
    @als5321 5 месяцев назад

    Most underrated channel on dev youtube. Keep it up!

  • @maintenance_informatique
    @maintenance_informatique 10 месяцев назад +1

    Thank you very much for this excellent video. How can I get in touch with you? by email or discord or linkedin

    • @Computerix
      @Computerix  10 месяцев назад

      Thank you! This is my linkedin: www.linkedin.com/in/charbel-el-helou-6523a5200/

  • @KhodeCamp
    @KhodeCamp 8 месяцев назад

    Thank you for your work hard. Can you help make more videos of multi-tenant with SQL (Postgres) please

    • @Webtech-nu7hq
      @Webtech-nu7hq Месяц назад

      ruclips.net/video/qR05wWeQ2OI/видео.htmlsi=H40Y7u4bZ12ugdHr