Support using `null` as ObjectId for GridStore #933

Closed
wants to merge 1 commit into from

2 participants

@Reggino

Regarding the GridStore constructor:

When null is supplied as ObjectId and an extra filename is passed, the GridStore will not try to query by filename.

This patch fixes this.

@christkv
mongodb member

are you trying to save a file using a filename then you just do

new GridStore(db, "filename", "w")

not

new GridStore(db, null, "filename", "w")

@Reggino

I got that now, but that wasn't obvious for me by looking at the code and/or the method signature: I thought passing an explicit null-value for the objectId would trigger a filename-based lookup. And besides: the typos in the code make it even more 'unclear'.

@christkv
mongodb member

yeah it's the hubris of legacy code. the second option is for setting a filename as metadata not as the id itself. The best options is usually to pass in a id and a filename.

@Reggino

The reason i came with this issue is this issue in gridfs-stream:

aheckmann/gridfs-stream#11

A 12-lettered (or 24 lettered) string/filename COULD internally be casted to an ObjectId (but this is not the case for GridStore). To prevent this possible mixup, i think it is a good idea to make it a bit more explicit whether a 'filename' or 'ObjectId' is passed

@christkv
mongodb member

yeah I know but I can't break backward compatibility and this pull request would as it would mange the last options object as you pointed out by modifying a test to make it pass.

@Reggino

That test was broken before i changed anything ;-) I think the change IS backwards compatible!

@Reggino

(i should not have added the test-change in the same pull request, sry)

@christkv
mongodb member

passes here an on travis without the changes so I'm not sure why it does not pass on you system

@Reggino

Reverted the (unrelated) test change

@Reggino

Typo: indexOf() never returns null

@christkv
mongodb member

Closing as not going to support

@christkv christkv closed this Jun 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment