gpt4 book ai didi

objective-c - Firebase,无法查询数组

转载 作者:行者123 更新时间:2023-11-30 12:02:01 24 4
gpt4 key购买 nike

我从this post了解到firestore 查询当前不提供以下场景。给定这样的数据:

somecollection/somedoc:
foos: [ { name:"foo" email:"foo@bar.com" }, ... ]
somecollection/someotherdoc:
foos: [ { name:"bar" email:"bar@foo.com" }, ... ]

我无法编写如下查询:

FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"foos.email" isEqualTo:@"foo@bar.com"];

另一个答案中的建议是创建我希望查询的数组字段的映射,使用值作为键。像这样的东西:

somecollection/somedoc:
foos: [ { name:"foo" email:"foo@bar.com" }, ... ]
emails: { "foo@bar.com": true, ... }
somecollection/someotherdoc:
foos: [ { name:"bar" email:"bar@foo.com" }, ... ]
emails: { "bar@foo.com": true, ... }

现在我的查询是:

FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"emails.foo@bar.com" isEqualTo:@(YES)];

但是这个查询没有返回任何文档,因为我认为电子邮件地址对于 map 键来说不是很好的语法。在其他潜在的噪音中,它包含一个点 .,我担心它会将 FIRQuery 视为取消引用运算符。

有人可以解释如何查询数组中的电子邮件(或任何其他看起来不适合作为 map 中的键的对象)吗?

最佳答案

查看标题,我发现有多种名为 queryWhereFieldPath:isEqualTo: 的查询,它采用 FIRFieldPath,并且字段路径似乎可以容忍否则被视为字段名称中的分隔符。它很容易形成和使用,如下所示:

FIRFieldPath *path = [[FIRFieldPath alloc] initWithFields:@[@"emails", @"foo@bar.com"]];
FIRQuery *query = [ref queryWhereFieldPath:path isEqualTo:@(YES)];

所以,是的。但奇怪的是,这个看似成熟的数据库却拥有如此玩具般的查询语言。

关于objective-c - Firebase,无法查询数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47102105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com