0

My system is designed so that every user has their own database with 3 collections inside.

I'm designing an admin system that need to connect to the user db when they log in - how do I design this using Mongoose?

I know that Mongoose has useDb that allow database switching, but if I do that for every user will I run into any concurrency issue? (User A performing something, User B login and switch the DB connection back)

createConnection is another viable option - however this means I need to require the model file and pass in the newly created connection everytime?

touchaponk
  • 404
  • 4
  • 17
  • Do you mean every user (id) has a different db or every user (type) has a different db ? – S.D. Jul 29 '16 at 05:33
  • I don't think that you can easily use Mongoose for this sort of setup. See [this question + answers](http://stackoverflow.com/questions/22588253/dynamic-database-connection-to-mongodb-or-mongoose-from-nodejs) for a (messy) solution. – robertklep Jul 29 '16 at 06:35
  • I don't think that this is good approach to create databases for users. What are you trying to make? maybe we can suggest you a better solution – Yaroslav Tkachenko Jul 29 '16 at 09:35
  • @YaroslavTkachenko we do this because we're running a B2B SaaS service and each client will store their own data in that database, completely isolated from each other. However to save overhead by not having to provide a separate web app runtime for every client we're designing a singe webui that can switch database back and forth. – touchaponk Jul 29 '16 at 10:36
  • @S.D. user ID, see my additional comment above if you wonder why :) – touchaponk Jul 29 '16 at 10:37

0 Answers0