0

My flutter app needs to count for unread messages. So far, when a message is created, no 'readDate' field is set.

Is it possible to have a where condition that tests the presence of the field?

final snapshot = await FirebaseFirestore.instance
        .collection(collectionName)
        .where("toUserId", isEqualTo: userId)
        //.where("unreadDate", isGreaterThan: 0). //<< Error
        //.where("unreadDate", isNull: true)

        .orderBy("creationDate", descending: true)
        .limit(limit)
        .withConverter<ClassifiedAdMessage>(
          fromFirestore: (snapshot, _) =>
              ClassifiedAdMessage.fromMap(snapshot.data()!),
          toFirestore: (message, _) => message.toMap(),
        )
        .get();
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
  • Nope, that's unfortunately not possible. Firestore queries are based on values that exist in its indexes, so you can only query for values that *are* present. – Frank van Puffelen Jan 31 '23 at 22:43

0 Answers0