I am trying to run an '$or' query with Morph. However although the query seems ok (by using getRawQuery) and can be executed against Mongo from the command line, I do not seem to be getting any results back from Morph.
I am using the following construct:
$query -> property('$or') -> equals(array(array('name' => 'layout)))
When I JSON encode the '$query -> getRawQuery()' I get the following:
This JSON snippet returns the expected result when I use the MongoDB command line. However I do not get anything back in my object from Morph.
Is it possible to use '$or' with Morph? If so is this the correct way of doing it? If not is there a way to perform an '$or' query using Morph?
Thanks for your quick responses and help with my queries. It is very much appreciated.
Please ignore my last post.
I retested the code and it does work.
Sorry for posting something that was not a problem.
Thanks for getting back to me.
I am trying to testing different fields for the same value. For example (excuse the SQL syntax)
SELECT name FROM profile WHERE id = '1234' OR nickname = '1234'
The code snippet that I posted does actually work, and it works with more than one field as I require. So what I have ended up with is as follows:
$query -> property('$id') -> equals(array(array("_id" => $template), array("name" => $template)))
and this does work, although I understand from what you say that it is not really supported in this way.
I used the getRawQuery() method to show me what the findByQuery() would actually execute on the Mongo server, it was just a way for me to test things.
Hope that helps clear it up a bit.
Yeah - That's fine. If you can think of a way to allow for $or queries in a more elegant way that would be good. Or even better fork the project, implemented the changes and issue a pull request :)
maybe something as simply as:
I made a method: