Open KTBsomen opened 5 days ago
We've run into similar issues before, what we've done in the past is the following, which puts all the connection models on the global mongoose.models
, so you can reference models from multiple connections by just doing require('mongoose')
for (const connection of mongoose.connections) {
for (const modelName of Object.keys(connection.models)) {
if (mongoose.models[modelName]) {
throw new Error(`Conflicting model ${modelName}`);
}
}
Object.assign(mongoose.models, connection.models);
}
It would be great to add something similar as a feature.
you are awesome. have you checked my implementation it's very easy just a single file.
Prerequisites
🚀 Feature Proposal
I just need more space so I created two different database and now I want to Marge all the database into single database so I can query it as a single database instance.
I just created a npm package called mongoplusplus to do the same. but I want this feature in native mongoose if possible.
also it dose the job well for my requirement but I am not 100% confident about the performance and security of my package and moreover the documentation kind of sucks so if anyone can help me evaluate the project that will be greatness at it's peak.
GitHub link of my package https://github.com/KTBsomen/mongoplusplus
Motivation
lack of money and low free tier of mongodb. nothing fits into 512 MB
Example
it will just work like i have connection uris of mongodb database i will pass them to my constructor it will handle all the connections.
now mejority of the function are the same like creating schemes, building models. one key difference is I will have some extra query method to query all the database at once or just anyone of them.
like so on. you can check my current implementation on GitHub
https://github.com/KTBsomen/mongoplusplus