示例数据:
我希望新的查询capabilites将允许查询嵌套的数据。但是,根据我所看到的,为了找到电子邮件地址为test2@test的帐户,我真的必须做两件事之一: $ account $ account $ b $ email $ $ $ $ $ $ $ $ $ $ $ test,mobile:+15555551001}, {account:simplelogin:002,email: test2@test,mobile:+15555551001}, {account:simplelogin:003,电子邮件:test3@test,mobile:+15555551003} ] 这些是我唯一的选择吗?是不是可以使用新的查询API来更深入地查询嵌套信息? 如果你的问题是我怎么能根据它的电子邮件获得一个账户?,然后: 请参阅jsbin以获取工作示例: jsbin/yikecu/1/edit?js,console 事实证明,OP为每个帐户都有一个嵌套的电子邮件地址集合,并希望根据一个电子邮件地址的存在来选择项目。 我确实不认为目前可以使用包含查询。因此,自己创建索引是最好的方法。我会保持该索引非常简单: 此索引假定每个电子邮件地址映射到至多一个帐户。如果这不符合您的使用情况,则需要相应地修改数据结构。 Now that the new query capabilities are out, I'm going to ask this question. It's similar to other questions where the answers were based on the old API. Example Data :
{
"accounts" : {
"simplelogin:001" : {
"email" : "test1@test",
"mobile" : "+15555551001",
... many more fields
},
"simplelogin:002" : {
"email" : "test2@test",
"mobile" : "+15555551001",
... many more fields
},
"simplelogin:003" : {
"email" : "test3@test",
"mobile" : "+15555551003",
... many more fields
}
}
I was hoping the new query capabilites would allow querying nested data. However, based on what I see, in order to find the account with the email address "test2@test", I really have to do one of two things:
[
{
"account": "simplelogin:001",
"email": "test1@test",
"mobile": "+15555551001"
},
{
"account": "simplelogin:002",
"email": "test2@test",
"mobile": "+15555551001"
},
{
"account": "simplelogin:003",
"email": "test3@test",
"mobile": "+15555551003"
}
]
Are these really my only options? Is it not possible to use the new query API to query deeper into nested info? If your question is "how can I get an account based on its email?", then: See this jsbin for a working sample: jsbin/yikecu/1/edit?js,console It turns out OP has a nested collection of email addresses for each account and want to select items based on the presence of one email addresses. I indeed don't think that a "contains" query is currently possible. So creating an index yourself is then the best approach. I would keep that index extremely simple: This index assumes that each email address maps to at most one account. If that does not fit your use-case, you'll need to modify the data structure accordingly.
更多推荐
在firebase中查询嵌套的数据
发布评论