解析:查询包含的指针

时间:2017-09-07 17:01:24

标签: javascript node.js mongodb parse-platform

我有一个“Product”集合,它有一个指向我在产品查询中包含的“Category”集合的指针。如何在不首先单独查询类别本身的情况下查询此类别值?

var productQuery = new Parse.Query("Product");
productQuery.include("category");

if(params.category) {
    productQuery.equalTo("category", params.category);
}

...

productQuery.find({
    success: function(products) {...},
    error: function(err) {...}
});

不想要

var productQuery = new Parse.Query("Product");
productQuery.include("category");

if(params.category) {
    var categoryQuery = new Parse.Query("Category");
    categoryQuery.equalTo("name", params.category);
    categoryQuery.first({
        success: function(foundCategory) {
            productQuery.equalTo("category", foundCategory);
        }
    });

    // Yes, I am aware that in this example the product query below would likely be executed before the category query above finishes.
}

...

productQuery.find({
    success: function(products) {...},
    error: function(err) {...}
});

1 个答案:

答案 0 :(得分:0)

您正在寻找的是Parse.Query上的matchesQuery或matchesKeyInQuery方法:http://parseplatform.org/Parse-SDK-JS/api/classes/Parse.Query.html#methods_matchesQuery