Querying Relationships #27

Closed
russellseymour opened this Issue Jan 19, 2012 · 1 comment

Comments

Projects
None yet
3 participants

Hello again,

I have created a 'HasOne' relationship in a document with one in another collection.

Is it possible to query the document based on this relationship? For example, I have the relationship field set as 'moduleid' and I want to query all documents that have a specific Id and an 'adminnav' value of 1. My query at the moment is thus:

$query ->property("moduleid")
             -> equals(id)
             -> property("adminnav")
             -> equals(1)

I have tried to use the Id as a string and as a MongoId but neither of them have worked so I am beginning to think that it is down to the way I am trying to use the relationship.

Am I barking up the wrong tree or is this possible? If it is possible please could you point me in the right direction?

Thanks for all your help. I am thinking of forking this so I can add the 'or' method and some other ideas I have had.

Regards,

Russell

Contributor

daniphp commented May 21, 2012

I found the answer on the mongo website
db.postings.find( { "author.name" : "joe" } );

You need to append the properties, in your case: moduleid.adminnav

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