简体   繁体   English

解析REST API的查询中OR和AND运算符的困难

[英]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. 我把Parse的REST API弄得一团糟,我认为缺少文档。

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. 我想进行查询并获取该特定表的所有行,其中username1在接收方或发送方字段中,而username2在接收方或发送方字段中。

Instead I am getting username1 "or" username2 which is clearly wrong because I also get rows with other usernames. 相反,我得到的是username1“或” username2,这显然是错误的,因为我还获得了具有其他用户名的行。

Here is my code and what I send to Parse 这是我的代码以及我发送给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 网址然后传递到CURL

If the sender and receiver can't be the same, then this JSON should do the trick. 如果发送方和接收方不能相同,则此JSON应该可以解决问题。 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. 它告诉Parse提取记录,其中发件人是用户1或用户2,而收件人是用户1或用户2。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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