These are chat archives for Automattic/mongoose

Aug 2015
Tom V
Aug 09 2015 03:08
@zxqfox Thanks for your comment. For testing that sounds sound. I with I better understood how it works when NOT passing in a mongoose instance. I guess I'll look at some github projects with mongoose and express.
Tom V
Aug 09 2015 03:14
Here's a good example from github of a server startup script. Each mongoose model is in it's own file and requires the mongoose library, and then after defining the schema, it' 'registers' it with it's instance of mongoose. I guess there's a bit of a magic if mongoose has already been required, and connected, before the scripts run, somehow registering a model in these scripts works, even though they are not given a explicit instance of the mongoose connection.
Tom V
Aug 09 2015 03:24
Ahhh, answering my own question, after reading a comment on stack overflow.. I was not aware of this but from the note documentation: "Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file."
Mongoose takes advantage of that by attaching the db connection to the mongoose object on that first require. Subsequent requires just get the same object, with it's connection attached. I tend to (incorrectly) of a module as static collection of functions.. code and learn. I'll see I can add something to the mongoose docs to help prevent others from my confusion.
Christian Blaschke
Aug 09 2015 20:10
hey! =) is it possible to pass an existing mongodb connection to mongoose constructor?