我又来自以下问题。
Add nested data in Firestore by flutter
我想提前知道这张地图上有多少辆汽车。 在这种情况下,我需要在汽车标签上编号才能更新(添加)。
'cars': {
'car1': {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
},
'car2': {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
}
}
在这种情况下,我要2。 还是更好的方法?请给我建议。
答案 0 :(得分:1)
您需要检索cars
地图:
_firestore.collection('members').document(${loginUser.uid}).get().then((value){
print(value.data);
Map<String,dynamic> cars = value.data["cars"];
print(cars.length);
});
检索文档,然后使用length
属性获取cars
映射中的元素数量。