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
349 stars 50 forks source link

Avoid creating multiple gridfiles with the same filename #5

Closed marcello3d closed 13 years ago

marcello3d commented 13 years ago

Either make gridfs.create() asynchronous, or make gridfile.save() asynchronous and have it search for an existing file if it has no _id.

The former would make the programmer more aware of what's going on, while the latter can cleanly use the existing api.

tarqd commented 13 years ago

Could make gridfs.create something along the lines of gridfs.create = function(descriptor, callback){ if(callback) { /* do it async /} else { / stick with non-async */}

and then do the same with save(). Seems that way you get the best of both worlds

marcello3d commented 13 years ago

I've decided to keep the API the same. gridfs.create returns immediately and doesn't actually save anything until you start writing to its write stream. file.save() now has an asynchronous callback to make this happen correctly.