firebase 中的 whereIn 查询是否有效?

Does whereIn in firebase query efficient?

我设计了这样一个数据模型

有一个 users 集合,其中包含一个订单 ID 字段存储数组。

当我需要有关该特定用户的所有订单的信息时,我使用这些 ID 从集合 orders 中获取数据。通过使用 whereIn

List<String> orderIds = (await FirebaseFirestore.instance
        .collection('')
        .doc(QnRWjhJbjViKUEVBvRAr)
        .get()).get('orders');
var result = FirebaseFirestore.instance
        .collection('orders')
        .where(FieldPath.documentId, whereIn: orderIds)
        .get();

我只是好奇。 whereIn 有效率吗?它会检查 orders 中的每个文档并测试该 id 是否在 orderIds 中吗?如果那是真的,当有更多数据(比如说数百万)时,这不会有性能问题吗?

Firestore 有非常明确的性能保证:获取结果仅取决于您检索的数据,完全独立于查询集合中存在的文档数量。所以不,whereIn 的性能不取决于集合的大小。