0

What is the order of operations for the mongodb-native driver?

Let's say you have a class that's purpose is to save a document of some sort and let's say it has a long life. How many times should open be called? Once per db write? When is close supposed to be called? Essentially I want a class method that looks like this:

  var myMongoClass = new MongoDB(server,port)
  myMongoClass.write_file(filename,callback)
  myMongoClass.write_doc(doc,callback)

I posted this a while ago and got it working: Problem with MongoDB GridFS Saving Files with Node.JS

It's now not working at all and failing with TypeError: Cannot read property 'md5' of null

Every time I work with this library I want to bang my head through a wall.

Community
  • 1
  • 1
Justin Thomas
  • 5,680
  • 3
  • 38
  • 63
  • I feel your pain. I've had lots of problems with mongoDB and mongoose (which you might like to try by the way). That's the nature of immature projects, the API changes from under your feet, documentation is sparse, often contradictory, and usually unhelpful. And it's frustrating when you compare it to the age-old SQL technologies that have been around longer than most programmers. A bit of a rant, but I sympathise. – davin Oct 21 '11 at 00:34

1 Answers1

0

It seems like the correct answer is create a client and keep that client open for the duration of the application (never explicitly calling close). I have a wrapper that keeps a reference to the connected client and my app only boots up if the connection is received.

Justin Thomas
  • 5,680
  • 3
  • 38
  • 63