Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remove and exist with _id type different of ObjectId #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ Grid.prototype.collection = function (name) {
*/

Grid.prototype.remove = function (options, callback) {
var _id;
if (options._id) {
_id = this.tryParseObjectId(options._id) || options._id;
options._id = this.tryParseObjectId(options._id) || options._id;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are now mutating the options object passed in, this is considered a bad practice and can lead to some hard to track down bugs...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you're right. I fixed the problem.

}
if (!_id) {
_id = options.filename;
}
return this.mongo.GridStore.unlink(this.db, _id, options, callback);

var gridStore = new this.mongo.GridStore(this.db, options._id, options.filename || null, "w", options, callback);
return gridStore.unlink(callback);
}

/**
Expand All @@ -103,14 +101,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);
}

/**
Expand Down