[英]Firestore REST API WHERE IN query
我正在尝试使用 Firestore REST API 执行以下查询,我发现文档对于更复杂的查询非常有限。 基本上我想使用 WHERE IN 查询。
const allowedIds = ['xxxx', 'zzzz', 'yyyy'];
let myQuery = firebase.firestore().collection('myCollection').where(firebase.firestore.FieldPath.documentId(), 'in', allowedIds);
这个效果很好,但现在我想转换它。 这是我迄今为止尝试过的:
const allowedIds = ['xxxx', 'zzzz', 'yyyy'];
'structuredQuery': {
'from': [{
'collectionId': 'myCollection',
}],
'where': {
'fieldFilter': {
'field': {
'fieldPath': firebase.firestore.FieldPath.documentId(),
},
'op': 'IN',
'arrayValue': {
'values': [
{
'stringValue': 'xxxx',
},
{
'stringValue': 'zzzz',
},
],
},
},
},
},
似乎问题在于使用 firebase.firestore.FieldPath.documentId() 来引用文档 ID,但是还有其他方法可以实现吗? 我目前收到的错误消息:
“'structured_query.where.field_filter.field' (field_path) 处的值无效,在标量字段上启动 object 收到无效的 JSON 有效负载。'structured_query.where.field.filter' 处的未知名称“arrayValue”:找不到
我的数据结构:我有车辆和用户collections。 用户有一个名为车辆的字段,它是一个字符串数组(车辆集合文档 id-s)。 所以我想在user.vehicles中查询车辆集合
尝试将firebase.firestore.FieldPath.documentId()
替换为"__name__"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.