Replies: 1 comment
-
The reason why the export schema pattern is typically less convenient is that you need to pass the connection or the models around as a parameter to the functions that use those connections/models. Can't just pull the model using async function startServer() {
// Waiting for my two connections to be established and models registered
const { conn1, conn2 } = await createConnections();
const MyModel = conn1.model('MyModel');
await myModel.find({...});
// Do stuff...
} I wrote a little bit about some of the patterns I use for this here: https://thecodebarbarian.com/using-ramda-as-a-dependency-injector |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using multiple mongoose connections with typescript as described in the official mongoose documentation:
https://mongoosejs.com/docs/connections.html#multiple_connections
After following this export schema pattern instead of the standard export module pattern, how do I go about actually querying my models? It's of high importance for me that I can await for the models to actually connect before the rest of my app starts querying the models.
As exporting models instead of the whole schema is significantly more convenient, how would I code up the connection creation to use it in a similar fashion?
App.ts:
Beta Was this translation helpful? Give feedback.
All reactions