简体   繁体   中英

Does whereIn in firebase query efficient?

I design a data model like this 在此处输入图像描述

在此处输入图像描述 there a users collection that has one field store array of order ids.

When I want information about all orders of that specific user, I use these ids to get data from collection orders . by using 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();

I just curious. Is whereIn effiecient? Does it check every single document in orders and test if that id is in orderIds ? If that true, when there're more data (let say millions) doesn't this will have performance issue?

Firestore has a very clear performance guarantee: getting results only depends on the data you retrieve and is completely independent of the number of documents that exist in the collection(s) queried. So no, the performance of whereIn doesn't depend on the size of the collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM