Start a new topic

Error in Documentation: Logical operators ("$or")

I have found what I believe to be a typing error/mistake in the REST API and I assume all other API's that use an array syntax to separate conditions for the "OR" operator.


The following passage is from: http://devcenter.kinvey.com/rest/guides/datastore#operators


"Similarly, to perform a logical OR, use the $or operator. The following query will return all entities that have a first name of James (even if the last name is not Bond), as well as all entities having a last name of Bond (even if the first name is not James)":


?query={"$or":[{"firstName":"James", "lastName":"Bond"}]}



This is incorrect and will return only those that have both first name "James" AND last name "Bond".


The corrected script should read:


?query={"$or":[{"firstName":"James"}, {"lastName":"Bond"}]}.


After some investigation and Google-ing, I believe I can explain this some more.


INCORRECT:

    [{"firstName":"James", "lastName":"Bond"}]

This has only one element in the array, and the element contains two Name/Value pairs, and effectively is an "AND" operator (correct me if I am wrong).



CORRECT:

    [{"firstName":"James"}, {"lastName":"Bond"}]

This has two element in the array, which will work as expected. i.e. getting all elements with first name "James" as well as all elements with the last name of "Bond"


ASSUMPTION:

If my assumption is correct i.e. multiple Name/Value pairs in an element act as an "AND" operator- then I would assume that the following query would return all entities that have the the first name of "James" AND the last name of "Bond" as well as all entities that have the last name of "Smith":


    [{"firstName":"James", "lastName":"Bond"}, {"lastName":"Smith"}]


If my assumption is correct I would like to suggest that this be mentioned in the API Documentation, as it would have saved me a lot of time.


I would like to stress that this is not a "dig" at the Kinvey guys, just trying to make myself useful and I could be completely wrong.

1 Comment

Hi Sagar,


Thanks for pointing this out. I will flag this documentation for update.


As Kinvey uses mongoDB in the backend, Kinvey queries follow the same format as mongoDB. You might want to refer mongoDB documentation if you run into a similar issue in the future.


Regards,

Wani

Login or Signup to post a comment