如何在Parse.com查询中找到所有用户*不*?

时间:2022-09-23 15:48:32

I have a "Logs" table that has a pointer to a User in the User table. I am trying to "Find all users without a log entry for the last N days". The following query, however, seems to return all users instead of the expected value.

我有一个“日志”表,在User表中有一个指向User的指针。我正在尝试“查找最近N天没有日志条目的所有用户”。但是,以下查询似乎返回所有用户而不是预期值。

Here is my current query:

这是我目前的查询:

var logsFrom = function(start, end) {
    // Query for all logs within the last 24 hours
    var Log = Parse.Object.extend("Log");
    var query = new Parse.Query(Log);

    query.greaterThanOrEqualTo("createdAt", start);
    query.lessThan("createdAt", end);
    return query;
};
var nonLogsFound = function(request, response) {
    Parse.Cloud.useMasterKey();

    // Midnight of the current day
    var end = new Date();
    end.setHours(0, 0, 0, 0);

    // Midnight of the previous day
    var time = (5 * 24 * 3600 * 1000);
    var start = new Date(end.getTime() - (time));

    var count = 0;
    var logQuery = logsFrom(start, end);
    var userQuery = new Parse.Query(Parse.User);
    userQuery.doesNotMatchKeyInQuery("objectId", "user", logQuery);
    userQuery.find({
        success: function(users) {
            // This returns *all* users.
            count = users.length;
            response.success("Query complete! (" + count + " results)");
        },
        error: function(error) {
            console.error(error);
            response.error(error);
        }
    });
};

Thanks

谢谢

1 个解决方案

#1


0  

Your query is matching an pointer ('user') against a string ('objectId'). That is why it's returning all results.

您的查询将字符串('user')与字符串('objectId')匹配。这就是它返回所有结果的原因。

Maybe changing

也许改变

userQuery.doesNotMatchKeyInQuery("objectId", "user", logQuery);

To

userQuery.doesNotMatchKeyInQuery("objectId", "user.objectId", logQuery);

I'm not sure if it supports keypaths though haven't tested.

虽然没有经过测试,但我不确定它是否支持密钥路径。

#1


0  

Your query is matching an pointer ('user') against a string ('objectId'). That is why it's returning all results.

您的查询将字符串('user')与字符串('objectId')匹配。这就是它返回所有结果的原因。

Maybe changing

也许改变

userQuery.doesNotMatchKeyInQuery("objectId", "user", logQuery);

To

userQuery.doesNotMatchKeyInQuery("objectId", "user.objectId", logQuery);

I'm not sure if it supports keypaths though haven't tested.

虽然没有经过测试,但我不确定它是否支持密钥路径。