[英]Firestore: Query documents by property of object
I've a collection with contacts with a structure like:我有一个包含联系人的集合,其结构如下:
name: 'XPTO Company',
emails: {
susan@xpto.com: { name: 'Susan', text: 'manager' },
fred@xpto.com: { name: 'Fred', text: 'marketing' }
}
How do I retrieve documents with email 'susan@xpto.com'如何使用电子邮件“susan@xpto.com”检索文档
Something like:类似的东西:
firebase.firestore().collection('contacts')
.where(new firebase.firestore.FieldPath('emails', email), '==', true).get()
.then(snap => {
})
You may add a property id
that holds the email address to your email object.您可以将包含电子邮件地址的属性
id
添加到您的电子邮件对象。 and replace '.'并替换'.' in email object key with '-', eg
susan@xpto-com
, so that your data structure looks like this:在带有“-”的电子邮件对象键中,例如
susan@xpto-com
,以便您的数据结构如下所示:
name: 'XPTO Company',
emails: {
susan@xpto-com: { id: 'susan@xpto.com', name: 'Susan', text: 'manager' },
fred@xpto-com: { id: 'fred@xpto.com', name: 'Fred', text: 'marketing' }
Then you can retrieve documents with email 'susan@xpto.com' in this way:然后,您可以通过以下方式使用电子邮件“susan@xpto.com”检索文档:
firebase.firestore().collection('contacts')
.where('emails.susan@xpto-com.id', '==', 'susan@xpto.com').get()
.then(snap => {
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.