-2

How can I do query with where in firebase? For example I want to access to the nameL of locationEvent in the estructure of the photo.

I am using flutter to code my app.

firebase photo

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mus
  • 67
  • 1
  • 13

1 Answers1

1

As shown in the doc, you can do as follows:

// Create a reference to the collection
final collectionRef = db.collection('collectionName');

// Create a query against the collection.
final query = collectionRef.where('locationEvent.${nameL}', isEqualTo: 'jkn');

// Execute the query
query.get().then(
  (res) => print("Successfully completed"),
  onError: (e) => print("Error completing: $e"),
);
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • But How can I do it if locationEvent is now an array with diferents locations? locationEvent=[{latitude:510,longitude:152,nameL:nameLocation},{latitude:5102,longitude:1522,nameL:nameLocation2}] – Mus Sep 26 '22 at 09:27
  • **This is a totally different case: behaviour for Maps and Arrays is different.** See this SO question/answer for an Array: https://stackoverflow.com/questions/54081799/firestore-to-query-by-an-arrays-field-value/54082731#54082731. I would suggest you duplicate your data and keep in your Firestore document a map or an array with **only** `nameL` values. – Renaud Tarnec Sep 26 '22 at 09:37