【发布时间】:2020-08-18 10:41:36
【问题描述】:
我有一个包含特定集合“用户”的文档 ID 的列表,我想获取仅存在于该列表中的文档,并且这些文档位于“用户”集合中,如前所述。
代码:
getUsers() async
{
double radius = 0.3;
String field = "GeoPosition";
print(currentUser.point.longitude);
GeoFirePoint center = geo.point(latitude: currentUser.point.latitude, longitude: currentUser.point.longitude);
var collectionRef = Firestore.instance.collection('user_locations').document(currentUser.pincode) .collection('Users_complete_address_and_geopoint');
this.stream = geo.collection(collectionRef: collectionRef).within(center: center, radius: radius, field: field, strictMode: false);
Future<List<certainrangeusers>> users1 = stream.first.then(
(documents) => documents.map((doc) => certainrangeusers(
id: doc['userPhone'],
)
).toList());
users1.then((val) async{
QuerySnapshot snapshot = await Firestore.instance.collection('users').where('id', isEqualTo: val.first.id).getDocuments();
List<User> users = snapshot.documents.map((doc) => User.fromDocument(doc)).toList();
setState(() {
this.users = users;
});
});
}
Firebase 结构: Click here for the firebase structure
图片格式的代码:
- 在橙色框中,“users1”是一个包含文档 ID 的列表...用户 10 公里用户
- 在粉红色框中,我们使用列表的值...
- 在绿色框中,我们需要传递上述列表中存在的文档 id...
Ps:我使用“val.first.id”只是为了将文档首先出现在列表中........但是我需要带上该列表中的每个文档......所以这就是我的观点……
【问题讨论】:
-
你能得到第一个id的文档吗?
-
@Adnankarim 我能够获得第一个 ID 的文档,我刚刚上传了 firebase 结构
-
查看我的回答,希望对您有所帮助。
标签: firebase flutter firebase-realtime-database google-cloud-firestore google-cloud-functions