Firestore Query Properties with special characters

和自甴很熟 提交于 2021-02-16 14:24:04

问题


I've a collection with contacts with a structure like:

name: 'XPTO' emails: { susan@xpto.com: 'Susan', fred@xpto.com: 'Fred' }

But the query will not return result: db.firestore().collection('contacts').where('emails.susan@xpto.com', '==', 'Susan').get().then(...

Because of the dot at "susan@xpto.com"

How to escape the dot?

I've tried `` and [ ] and didn't work.


回答1:


The documentation that suggests you should escape fields using backticks is actually not correct. It's in the process of being fixed. Instead, you should use FieldPath to build a path to the field to query:

db.firestore()
.collection('contacts')
.where(new FieldPath('emails', 'susan@xpto.com'), '==', 'Susan').


来源:https://stackoverflow.com/questions/49396148/firestore-query-properties-with-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!