find by nested document _id no longer works #389

Closed
henryoswald opened this Issue Jun 25, 2011 · 6 comments

Comments

Projects
None yet
2 participants

This used to work in previous versions (1.1.2), I am not quite sure where it stopped working

example:
User.findOne({'arrayOfNestedDocs._id' : some_id}, function(err,user){.....

aheckmann closed this Jun 29, 2011

Thank you, however do you know the syntax for entering an id into a query from a request? The test pulls an Id from an object however if I try and just hard code an _id in it fails.

example which will find nothing:
User.findOne({'arrayOfNestedDocs._id':'4e136e38c7d4b32e70000004'}, function(err,user){..........

I can find by top level _id's and all properties apart from id.

aheckmann reopened this Jul 5, 2011

Collaborator

aheckmann commented Jul 5, 2011

Turns out that finding with ObjectIds works but strings doesn't. We should be casting those ids. For now you can

var ObjectId = require('mongoose').Types.ObjectId;
User.findOne({'arrayOfNestedDocs._id': new ObjectId('4e136e38c7d4b32e70000004')}, function(err,user){..........

thanks, I thought of that as well but express throws an error up when trying to do it:
"This is an abstract interface. Its only purpose is to mark fields as ObjectId in the schema creation."

Collaborator

aheckmann commented Jul 5, 2011

are you sure you're using require('mongoose').Types.ObjectId ?

Ah ha! no I was using require('mongoose').Schema.ObjectId

Thank you very much for the quick responses!

henryoswald closed this Jul 5, 2011

aheckmann reopened this Jul 6, 2011

Collaborator

aheckmann commented Jul 6, 2011

reopening until we take care of that casting issue.

@ybogdanov ybogdanov pushed a commit to ybogdanov/mongoose that referenced this issue Jul 7, 2011

@aheckmann aheckmann update #389 test so it fails 7f4a575

@aheckmann aheckmann added a commit that referenced this issue Jul 25, 2011

@aheckmann aheckmann fix test for #389 be57a16

aheckmann closed this in fff744e Jul 25, 2011

@aheckmann aheckmann added a commit that referenced this issue Jul 25, 2011

@aheckmann aheckmann fix test for #389 0f3308b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment