Flutter 如何使用dart更新firestore查询中的值
下面是一个从firestore数据库返回一些数据的查询。 在获得文档之后,我想在返回最终列表之前更新一个特定的键(距离)值Flutter 如何使用dart更新firestore查询中的值,flutter,dart,Flutter,Dart,下面是一个从firestore数据库返回一些数据的查询。 在获得文档之后,我想在返回最终列表之前更新一个特定的键(距离)值 return db .collection(Global.marketplaceRef) .where("point.geohash", isGreaterThanOrEqualTo: range.lower) .where("point.geohash", is
return db
.collection(Global.marketplaceRef)
.where("point.geohash", isGreaterThanOrEqualTo: range.lower)
.where("point.geohash", isLessThanOrEqualTo: range.upper)
.limit(20)
.snapshots()
.map((list) => (list.docs
.map((e) {
// Update value here before returning doc.
// This doesn't seem to do that
return (e.data().update('distance_away', (value) => 100.toString())).toList();
})
).toList()
);
我想更改每个文档的距离值。您需要访问引用对象,而不是。data()尝试类似的操作
.map((list) => (list.docs
.map((e) {
return (e.reference.update({'distance_away': ['100']}
).toList()
这似乎可以解决问题,但查询似乎永远不会结束,它返回的DocumentReference与DocumentSnapshot类型不匹配。当然,因为.update函数无效,您不能使用。map()您应该首先获取文档,然后使用.forEach()更新文档