Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Using '$or' criteria #26
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:
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.
The property() function is for object properties not operators. Sadly
Also, you shouldn't actually need to call getRawQuery() at all. You can
Basically $or has not really been tested. I am also not sure exactly
or if you wanted an or on the name property you can do:
Tangent / One Australia Pty
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:
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: