I asked my question in the mongodb forum, but didn't get an answer. I
figure someone here may be able to tell me whats wrong
I have the following function in Node (I'm using the mootools server
side library):
query: function(collectionName, searchKey) {
connection.open(function(err, client) {
if (err) throw err;
collection = mongo.Collection(client, collectionName);
collection.find(searchKey).toArray(function(err, nodes) {
this.emit('data', nodes);
connection.close();
}.bind(this));
}.bind(this));
}
It works just fine, however, I want to put the connection.close() line
at the bottom of the function instead of in the collection.find block
(in case theirs an error with the database or something). Problem is
when I do that the database gets closed before the query. I think its
happening because of the async model node uses. Is there a way to get
around this issue?