解析-查询数组中指针的值

时间:2018-08-30 23:33:35

标签: ios mongodb parse-server

如果我有一个指向数组中多个_User对象的指针,我可以查询一个User的值。

例如 我有一个类Groups和一个数组membersmembers = [user1, user2, user3]。 我可以做类似的事情吗?

PFQuery *query = [PFQuery queryWithClassName:@"Groups"];
[query whereKey:@"members.name" isEqual:@"James"];

1 个答案:

答案 0 :(得分:0)

这可以通过嵌套查询来完成。创建一个“ innerQuery”以查找符合条件的用户。然后用Group约束whereKey:matchesQuery:查询。

PFQuery *innerQuery = [PFUser query];
// note that referring to the "name" field only makes sense if you've
// added a name field to User (you might mean username here)...
[innerQuery whereKey:@"name" isEqual:@"James"];

// now the main query is setup to match the innerQuery
PFQuery *query = [PFQuery queryWithClassName:@"Groups"];
[query whereKey:@"members" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
}];