繁体   English   中英

Parse.com或查询

[英]Parse.com OR query

我正在尝试使用OR查询来获取每个查询结果的最新注释,因为Promise缓慢且昂贵:

    var queries = [];
    _.each(videos, function (video) {
        var mostRecentCommentsQuery = video.relation("comments").query();
        mostRecentCommentsQuery.descending("createdAt");

        mostRecentCommentsQuery.include("creator");
        mostRecentCommentsQuery.include("mentions");

        mostRecentCommentsQuery.limit(4);

        queries.push(mostRecentCommentsQuery);
    });

    var commentQuery = new Parse.Query.or.apply(this, queries);
    return commentQuery.find();

并得到此错误:

Failed with: TypeError: function apply() { [native code] } is not a constructor
    at Parse.Promise.when.then.then.then.next_page (functions.js:82:28)
    at e (Parse.js:2:3909)
    at Parse.js:2:3459
    at Array.forEach (native)
    at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
    at c.extend.resolve (Parse.js:2:3410)
    at i (Parse.js:2:2901)
    at b.Promise.is.a.then.g.(anonymous function) (Parse.js:2:2992)
    at e (Parse.js:2:3909)
    at Parse.js:2:3459

但是做var commentQuery = Parse.Query.or.apply(this, queries); 什么也没做。 有什么建议么?

编辑:
我固定了最初的部分; 我从未检查过评论是否与拥有它们的视频相关联。 不幸的是,这导致了一个新的问题,即查询不受限制。 例如:

返回的第一个视频有6条评论。 应该返回最近的4条评论。 返回所有6个,这可能导致响应时间变慢和数据不准确。

有没有一种方法可以在OR查询中强制执行每个子查询的限制?

您可以对组合查询设置限制:即

commentQuery.limit(4);

暂无
暂无

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

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