marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

Connection closed ? #19

Closed hullionhero closed 13 years ago

hullionhero commented 13 years ago

When using mongodb native or mongoose the connection's always open when the server is started.

so I can do:

  db.collection('comment', function (err, collection) {
    server.db.comment = collection
  });

and then I have server.db.comment always available to add to.

But in Mongolian the connection seems to close immediately? Is this intended behavior? Am I misunderstanding the message?

Thanks.

marcello3d commented 13 years ago

In Mongolian DeadBeef there are only callbacks for operations that actually get data from the server, so your code above should be written as:

server.db.comment = db.collection('comment')

Mongolian has its own connection management. It will connect as needed and automatically close the connection after a period of inactivity.

You can override this behavior by passing a {keepAlive:MS} option:

var mongo = new Mongolian({ keepAlive:15000 })

A keepAlive of zero or false will keep the connection open until you call close explicitly:

var mongo = new Mongolian({ keepAlive:0 })
hullionhero commented 13 years ago

Is having Mongolian manage the connection useful? Should I set keepAlive to 0? If an app is reasonably active you're going to need data from the db all the time, what's the reason for closing the connection?

Thanks.

hullionhero commented 13 years ago

To put it another way, I think in my usecase I would rather have the connection for being always on. Would there be any downsides?

marcello3d commented 13 years ago

I agree with you. For the tests it made sense to have the connection close when it's no longer needed, but the default should probably keep the connection alive.

hullionhero commented 13 years ago

OK thanks, was just making sure I wasn't doing something stupid.