How to get a Map stored in Cloud Firestore with Dart/Flutter ? I tried this but it only works with Array :
Firestore.instance
.collection(\'posts\')
It doesn't really make sense for userlist
to be an array here. Firestore doesn't let you query for values of maps inside an array. Just store it as a map. If userlist
was just a map of uid/value pairs, you could query it like this using dot notation:
Firestore.instance
.collection('posts')
.orderBy('createdAt', descending: true)
.where('userlist.' + userId, isEqualTo: true)
.snapshots(),
Just adding to Doug Stevenson's answer, I had to use the key isGreaterThan: ''
in order to not get an empty array.
Firestore.instance
.collection('posts')
.where('userlist.' + userId, isGreaterThan: '')
.snapshots(),
I don't recommend your way of data model. Because of some limitations as below:
So, better I would recommend you to use documents for each user.