我试图找到之前没有使用云功能连接的用户。我使用的表很少:
代码:
Parse.Cloud.define("findFreshUser", function(request, response) {
Parse.Cloud.useMasterKey(); // For reading all the table //
var user = Parse.User.current();
// Get all possible users we already connected to //
var connectQuery = new Parse.Query("Connected");
connectQuery.include('userId2');
connectQuery.equalTo("userId", Parse.User.current().id);
// Get all users with availability of '0' //
var availableQuery = new Parse.Query("Available");
availableQuery.notEqualTo("counter", 0);
var freshUserQuery = new Parse.Query(Parse.User);
freshUserQuery.doesNotMatchKeyInQuery("objectId", "userId2", connectQuery); // We haven't connected before - THIS DOEN'T WORK !!! //
freshUserQuery.doesNotMatchKeyInQuery("objectId", "userObjectId", availableQuery); // We won't use '0' availability users - THIS WORKS //
freshUserQuery.equalTo("hasLight", false); // user must not have a light //
freshUserQuery.descending("updatedAt");
freshUserQuery.limit(1); // We need only 1 user //
freshUserQuery.find({
success: function(results) {
if (results.length>0){
console.log("Found the user "+ results[0].id);
response.success(results[0].id);
}else{
response.error("No user found");
}
},
error: function() {
response.error("No user found");
}
});
});
由于某种原因,当使用2个doesNotMatchKeyInQuery语句时,CloudCode完全忽略connectQuery(所有其他语句都没问题):
仅使用
时freshUserQuery.doesNotMatchKeyInQuery("objectId", "userId2", connectQuery);
并注释掉
freshUserQuery.doesNotMatchKeyInQuery("objectId", "userObjectId", availableQuery);
确实有效。所以我认为与同时使用两者相关,它们可能相互冲突。我需要做什么才能同时申请?
感觉这是一个解析问题,但我对CloudCode来说真的很新,所以它可能是我做得不对的。
注意:请注意,我甚至不会比较用户对象本身,而是比较它的ID(这是隔离问题的一部分)。意思是,我知道我可以使代码和数据库更好。
答案 0 :(得分:-2)
你必须使用Promise来实现这样的查询:blog.parse.com/learn/engineering/whats-so-great-about-javascript-promises /