These are chat archives for Automattic/mongoose

Aug 2015
Tom V
Aug 08 2015 18:15
I'm not clear on the best way to structure a mongoose/express app. I can put each model in a separate file, but should that file be a function, that gets the mongoose connect object, e.g. module.exports=function(mongoose){ ... return mongoose.model('myModel', mySchema'); }
the examples I'm looking at don't do that, but how do, Model.find... work without a connection to the db?
I'd be happy to update the docs once I understand this, they are not clear, all samples assume you are inside the event emitter : db.once('open', function (callback) { //all my code for express goes here?? })
Alexej Yaroshevich
Aug 08 2015 18:59
It depends on your own needs, actually. If you want to test your app then better to make an instance of mongoose and provide it to each model-file (then you need function)
@TomV it just caches requests and trying to connect to db before resolving them