简体   繁体   中英

Difficulties with OR and AND operator in queries for Parse REST API

I am messing arround with the REST API of Parse and in my opinion the Documentation is lacking.

What I want to make a query and get all rows of that particular table where username1 is either in the receiver or in the sender field "and" username2 is either in the receiver or in the sender field.

Instead I am getting username1 "or" username2 which is clearly wrong because I also get rows with other usernames.

Here is my code and what I send to Parse

 $aWhere = array('$or' => array(
                            array('receiver' => $sUsername1),
                            array('sender' => $sUsername1)
                          ),
                  '$or' => array(
                            array('receiver' => $sUsername2),
                            array'sender' => $sUsername2)
                          ) 
                 );

$url = 'https://api.parse.com/1/classes/test?where='.json_encode($aWhere);

url then gets passed into CURL

If the sender and receiver can't be the same, then this JSON should do the trick. It tells Parse to fetch records where the sender is either user 1 or user 2 and the receiver is user 1 or user 2.

{
    "where": {
        "sender": {
            "$in": ["user 1", "user 2"]
        },
        "receiver": {
            "$in": ["user 1", "user 2"]
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM