如果我尝试使用
containedIn
过滤数据,如下所示,我将得到空结果,因为我尝试从指针列类型 userProfile
进行过滤,尽管我在查询中包含 userProfile
。
但是,我尝试将
containedIn
直接用于 User
中的另一个数组列,似乎工作正常。下面的这种查询不起作用吗?还有什么替代解决方案?
const query = new Parse.Query('User');
query.equalTo('accountType', 'Student');
query.include('userProfile');
// search.subjects is an array
query.containedIn('userProfile.subjectsIds', search.subjects);
不幸的是,您无法对包含的对象执行 containsIn() 。为了让 containsIn() 工作,它必须在您正在查询的类的列上执行。
换句话说,您必须直接在 userProfile 类上执行此查询,containedIn() 才能工作
晚了“一点点”,但绝对有可能。要查看使用查询的示例(如您所愿),请查看此处,从第 595 行开始:
查找示例的最简单方法是在解析存储库中进行测试,至少对我来说是这样。
如果你想在聚合管道中执行此操作,只需将 $match 阶段与 $in 一起使用,如下所示,其中
{
$match: {
_p_<column_name>: { "$in": ids.map((id) => "table_name$"+id)}
}
}
我认为使用 MongoDB 控制台也非常有启发性。