Home > database >  Does whereIn in firebase query efficient?
Does whereIn in firebase query efficient?

Time:04-25

I design a data model like this enter image description here

enter image description here 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?

CodePudding user response:

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.

  • Related