meanjs / generator-meanjs

MEAN.JS Official Yeoman Generator
http://meanjs.org/
473 stars 178 forks source link

How to change the mongodb connection once created #176

Closed srapelly closed 8 years ago

srapelly commented 8 years ago

Hi,

I have a requirement, i want to use multiple mongodb connections like mongodb://localhost/mean-dev1 mongodb://localhost/mean-dev2

i have a menu, where i can select the category, based on that, i want to switch my mongoose connection point to different.

how can i do this? how should I reset the session.

Please help me in this regards.

Thanks Satya

codydaig commented 8 years ago

@srapelly Your app should always maintain a connection to the mongodb. What if User1 is using mean-dev1 but User 2 is using mean-dev2? So, in this case you would need to open and maintain 2 db connections. What's for reasoning for having multiple db connections?

srapelly commented 8 years ago

Thanks you sir replying the post. We have requirement, where we capturing data for academic project. One database i will use it for application login, manage users etc. but we have academics category (say c1, c2, c3), i want to enter the subjects, topics, assessments, exams etc under each category. subject, topics, assessments etc schema's are same but i want to push this set into different databases like mean-dev-c1, mean-dev-c2, mean-dev-c3.

for instance if users into application with mean-dev but if he choose c1 (dropdown), i want to display subjects, topics, assessments related to c1. like wise.

Otherwise, if i want to maintain one mongodb, my subjects, topics, assessments, questions etc will be grow like anything. hard to manage and i want to control by deviding data into different databases.

ilanbiala commented 8 years ago

I think this is more custom than our generator allows (if it is truly necessary) and you'd be better off doing this in the config once you have generated the app.

mleanos commented 8 years ago

I agree with @ilanbiala

@srapelly IMO, each database should be it's own API (maybe different backend as well). However, in the use case you described it doesn't make sense to separate into multiple databases. You should create relationships to your models for your few categories.

If this truly is a requirement, then you can customize the mongoose config, just as Ilan said. Each model (other than User) would have to be registered with all category db's. I don't know the exact implementation, but you can probably find some help on Mongoose's GitHub.

srapelly commented 8 years ago

@mleanos thank for your response. I want to manage to register model with all category dbs. I want to use createConnection and con.model('model', new Schema({ .. }).

srapelly commented 8 years ago

Hi All,

I want to use mysql db along with mongo for the purpose of storing customer related information, organizations, groups, user activitity, reporting etc

How can i use mysql same as mongo db, maintaining the connection in the session?

thanks

ilanbiala commented 8 years ago

MySQL and mongodb use different schemes as one is SQL and the other is NoSQL. Please use Stack Overflow, Gitter, or another forum fort hinges other than bugs and features.