以下是我在firestore中保存用户geohash
和的方式geopoint
。
我的问题是我不知道如何检索g.geohash
或g.geopoint
从 Firestore 中检索。
例如,如果我想读取 field intro
,我就这样写代码;
FirebaseFirestore.instance.collection('...').doc(..).data()['intro']
但我不知道如何从 firestore 中检索g.geohash
和检索g.geopoint
。g.geohash
在地图内,并且g.geopoint
是地图内的数组。如何从我的 Firestore 中检索类似 map 字段g.geohash
和 array-inside-a-map 字段g.geopoint
?
无法读取文档中字段的子集。您必须获取整个文档,然后使用点符号或 FieldPath 来获取嵌套数据:
FirebaseFirestore.instance
.collection('users')
.doc(userId)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
try {
dynamic nested = snapshot.get(FieldPath(['g', 'geopoint']));
} on StateError catch(e) {
print('No nested field exists!');
}
} else {
print('Document does not exist on the database');
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句