Danniel Magno
Danniel Magno

Reputation: 304

Doctrine QueryBuilder don't working with DBRef

I currently have a field on a document of the posts collection which is a ReferenceOne to a collection of users. Querying on the shell db.posts.findOne({"usuario_stream.$id": ObjectId("5012d7674dfbad7f4e000084")}) works fine, but using the QueryBuilder it simply doesn't works.

$this->doctrine->createQueryBuilder('Documents\Posts')->field('usuario_stream.$id')->equals(new MongoId('5012d7674dfbad7f4e000084'))->eagerCursor(true)->getQuery()->execute(); on profiler shows { "$query" : { "usuario_stream.$id" : null }, "$orderby" : [ ] }.

I'm doing anything wrong?

Upvotes: 2

Views: 1773

Answers (1)

Alex Ross
Alex Ross

Reputation: 3839

It should work if you query on usuario_stream.$id using the ID as a string rather than an instance of MongoID:

->field('usuario_stream.$id')->equals('5012d7674dfbad7f4e000084')

Upvotes: 3

Related Questions