0

I have a Firebase collection that I want to query by a value inside an array of Maps.

enter image description here

So I want to query the documents inside the "products" collection by the value of "id" inside the "shops" array. I have used the following code in Flutter but it returns an empty list.

 var snap = await _productsCollection
    .where('shops', arrayContains:  {'id': mid})
    .where('isActive', isEqualTo: true)
    .get();

How can I get the result I want correctly?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • arrayContains only finds array elements that **exactly and entirely** match the given value. Your shops array contains objects that aren't exactly equal to the given value. In fact, the query you're trying to do is not possible with the data you have available. Consider making a new array that contains only IDs that you want to match. – Doug Stevenson Jun 06 '23 at 04:49

0 Answers0