TypeError: Cannot call method 'toString' of undefined when searching by id in document array and _id is not define #897

Closed
gubarez opened this Issue May 7, 2012 · 2 comments

Projects

None yet

2 participants

@gubarez
gubarez commented May 7, 2012

I don't have git right now, but the problem occurs here, when invoking this[i].get('_id').toString()), line 75:40

MongooseDocumentArray.prototype.id = function (id) {
try {
var casted = ObjectId.toString(ObjectIdSchema.prototype.cast.call({}, id));
} catch (e) {
var casted = null;
}

for (var i = 0, l = this.length; i < l; i++) {
if (!(this[i].get('_id') instanceof ObjectId)) {
if (String(id) == this[i].get('_id').toString())
return this[i];
} else {
if (casted == this[i].get('_id').toString())
return this[i];
}
}

return null;
};

@aheckmann
Collaborator

thanks for the report.

@aheckmann aheckmann closed this in 2385a92 May 7, 2012
@aheckmann aheckmann added a commit to aheckmann/mongoose that referenced this issue May 7, 2012
@aheckmann aheckmann handle DocArray#id when doc has no id
closes #897
d01b3c9
@gubarez
gubarez commented May 8, 2012

Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment