Differences between createConnection and connect

1,481 views
Skip to first unread message

Chad Lung

unread,
Jan 21, 2012, 11:16:12 PM1/21/12
to Mongoose Node.JS ORM
I was doing some unit testing against a project and found that
nodeunit will hang when I use mongoose.connect() as the connection is
never closed in the unit test or the module I'm talking to. Calling
mongoose.disconnect() doesn't work when mongoose.connect() is used to
open the connection. I switched to mongoose.createConnection() and
can then call mongoose.disconnect() and my unit test shuts down
cleanly and the connection is released. Since createConnection is
really for supporting multiple connections (according to the current
docs), what is the best practice to use mongoose.connect() in a unit
test and cleanly close the connection?

Thanks.

Aaron Heckmann

unread,
Jan 27, 2012, 2:37:02 PM1/27/12
to mongoo...@googlegroups.com
the only trouble i've had is that mongoose uses the autoReconnect option of the driver which causes the connection to re-open when another operation is attempted on a closed connection. its probably just a race condition where another test runs something after you call mongoose.disconnect(). we probably need a permantent close option or smth


--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en



--
Aaron


Morgan Craft

unread,
Apr 25, 2012, 5:45:24 PM4/25/12
to mongoo...@googlegroups.com
I've had this issue as well.  Prototyping a game world generator using nodejs/mongoose.  Once my generator script is done executing and I close the mongoose connection I can see in the code all my mongoose callbacks fire afterwards which I'm assuming established the autoReconnect which then causes my generator script to hang.  

On the top level I can refactor my code and maybe wrap portions in an async-lib to help manage this issue, but when I'm in this initial prototyping phase it would be nice to just have a way to kill the connection.




--
Aaron



For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en



--
Aaron


Aaron Heckmann

unread,
Apr 25, 2012, 7:37:53 PM4/25/12
to mongoo...@googlegroups.com
Yeah there is an option in the driver now for this. We'll get this in for 3.x


For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
Reply all
Reply to author
Forward
0 new messages