Firestore通过数组的字段值查询 [英] Firestore to query by an array's field value

查看:93
本文介绍了Firestore通过数组的字段值查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,查看我的数据库结构:

For instance, look at my database structure:

我想运行与此类似的查询:

I want to run a query similar to this:

db.collection('identites').where("partyMembers", "array-contains", {name: "John Travolta"})

实现此目标的正确方法是什么,甚至使用Firestore也可以吗?

谢谢.

推荐答案

array-contains操作检查数组是否包含特定(完整)值.它无法检查对象数组是否包含具有特定属性值的项目.

The array-contains operations checks if an array, contains a specific (complete) value. It can't check if an array of objects, contains an item with a specific value for a property.

执行查询的唯一方法是在文档中添加一个仅包含您要查询存在的值的附加字段.例如:partyMemberNames: ["John Travolta", "Olivia Newton"].

The only way to do your query, is to add an additional field to your document with just the value you want to query existence on. So for example: partyMemberNames: ["John Travolta", "Olivia Newton"].

这篇关于Firestore通过数组的字段值查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆