gpt4 book ai didi

javascript - Parse - 创建两个 OR 查询的 AND 查询

转载 作者:行者123 更新时间:2023-11-30 09:58:04 25 4
gpt4 key购买 nike

我需要在 Parse.com(伪语言)中执行以下查询:

select all posts where 
(expired < today OR expired not exists)
AND
(owner is {user} OR commenter contains {user})

我知道在 Javascript 中我可以使用 Parse.Query.or 创建两个 OR 查询,但是因为似乎没有 Parse.Query.and变体,我不知道如何将这两个 OR 查询组合成一个查询。

其他人建议简单地多次使用 equalTo 来创建 AND 语句,但这不适用于组合 OR 查询。

最佳答案

我不熟悉 Parse,这对于评论来说太长了,但请参阅下面的 documentation ;特别是最后一句话似乎就是您所追求的。

Compound Queries

If you want to find objects that match one of several queries, you can use Parse.Query.or method to construct a query that is an OR of the queries passed in. For instance if you want to find players who either have a lot of wins or a few wins, you can do:

var lotsOfWins = new Parse.Query("Player");
lotsOfWins.greaterThan("wins", 150);

var fewWins = new Parse.Query("Player");
fewWins.lessThan("wins", 5);

var mainQuery = Parse.Query.or(lotsOfWins, fewWins);
mainQuery.find({
success: function(results) {
// results contains a list of players that either have won a lot of games or won only a few games.
},
error: function(error) {
// There was an error.
}
});

You can add additional constraints to the newly created Parse.Query that act as an 'and' operator.

关于javascript - Parse - 创建两个 OR 查询的 AND 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33062395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com