diff --git a/lib/index.js b/lib/index.js index a892c55..5cd0b26 100644 --- a/lib/index.js +++ b/lib/index.js @@ -85,14 +85,13 @@ Grid.prototype.collection = function (name) { */ Grid.prototype.remove = function (options, callback) { - var _id; + var _id = null; if (options._id) { _id = this.tryParseObjectId(options._id) || options._id; } - if (!_id) { - _id = options.filename; - } - return this.mongo.GridStore.unlink(this.db, _id, options, callback); + + var gridStore = new this.mongo.GridStore(this.db, _id, options.filename || null, "w", options, callback); + return gridStore.unlink(callback); } /** @@ -103,14 +102,13 @@ Grid.prototype.remove = function (options, callback) { */ Grid.prototype.exist = function (options, callback) { - var _id; - if (options._id) { - _id = this.tryParseObjectId(options._id) || options._id; - } - if (!_id) { - _id = options.filename; - } - return this.mongo.GridStore.exist(this.db, _id, options.root, callback); + var query = {}; + if (options._id) + query._id = this.tryParseObjectId(options._id) || options._id; + if (options.filename) + query.filename = options.filename; + + return this.mongo.GridStore.exist(this.db, query, options.root, options, callback); } /**