Home > other >  In firebase searching main collection using sub collection reference
In firebase searching main collection using sub collection reference

Time:12-06

We have a collection called customer that has all the details and another collection called merchant with a sub-sub-collection called merchant customers where we are paginating the customers.

We need to search the customer using the main customer document fields with pagination using the reference from merchant sub-collection.

Customer Main records Customer Records

Sub-Sub-collection enter image description here

CodePudding user response:

Firestore queries can only filter (and thus also only paginate) on values that are present in the documents that it returns. There is no way to filer a document on values from somewhere else in the database.

So to allow the use-case, you will either have to replicate the relevant information from the subcollection into the main customer document, or replicate the information from the main customer document into the documents in the subcollection and then query that.

  • Related