Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

GridStore reference by filename not working #930

Closed
wants to merge 1 commit into from

2 participants

Tim de Koning Christian Amor Kvalheim
Tim de Koning

The feature of the GridStore to lookup a file by it's name just didn't work. This patch should fix that.

As a side note: maybe this feature should be removed AT ALL. Since file names don't have to be unique, the behavior is a bit unpredictable. For a read operation you can't know for sure whether the requested file is correct, for a write operation it's not obvious if you are creating a new file, or appending / overwriting an existing one...

Christian Amor Kvalheim
Collaborator

can you add a failing test ?

you can run the tests by doing

node test/runner.js -t functional

make sure you have mongod in your path so the test runner can find it

Tim de Koning

Continued in pull request #933 (sorry for the fuss)

Tim de Koning Reggino closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 06, 2013
Tim de Koning Reggino GridStore reference by filename not working 4fcc25c
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 3 additions and 3 deletions. Show diff stats Hide diff stats

  1. +3 3 lib/mongodb/gridfs/gridstore.js
6 lib/mongodb/gridfs/gridstore.js
@@ -40,7 +40,7 @@ var REFERENCE_BY_FILENAME = 0,
40 40 *
41 41 * @class Represents the GridStore.
42 42 * @param {Db} db A database instance to interact with.
43   - * @param {Any} [id] optional unique id for this file
  43 + * @param {ObjectID} [id] optional unique id for this file
44 44 * @param {String} [filename] optional filename for this file, no unique constrain on the field
45 45 * @param {String} mode set the mode for this file.
46 46 * @param {Object} options optional properties to specify.
@@ -83,7 +83,7 @@ var GridStore = function GridStore(db, id, filename, mode, options) {
83 83 this.fileId = new ObjectID();
84 84 }
85 85 } else {
86   - this.referenceBy = REFERENCE_BY_ID;
  86 + this.referenceBy = ((id === null || id === undefined) ? REFERENCE_BY_FILENAME : REFERENCE_BY_ID);
87 87 this.fileId = id;
88 88 this.filename = filename;
89 89 }
@@ -170,7 +170,7 @@ var _open = function(self, callback) {
170 170
171 171 // Create the query
172 172 var query = self.referenceBy == REFERENCE_BY_ID ? {_id:self.fileId} : {filename:self.filename};
173   - query = null == self.fileId && this.filename == null ? null : query;
  173 + query = null == self.fileId && self.filename == null ? null : query;
174 174
175 175 // Fetch the chunks
176 176 if(query != null) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.