问题
I'm from following issue.
How to manage add and update data in Firebase
Initially I can make data in firestore following code.
However I would like to add car2
inside of cars
after car1
.
I have no idea of it.
_firestore.collection('members').document(${loginUser.uid}).setData({
'cars': {
'car1': {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
}
}
Please give me advice.
回答1:
To add cars2
, then do the following:
_firestore.collection('members').document(${loginUser.uid}).updateData({
"cars.car2": {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
}
回答2:
Firestore.instance.collection(city).document('Attractions').updateData({"data": FieldValue.arrayUnion(obj)});
来源:https://stackoverflow.com/questions/61929827/add-nested-data-in-firestore-by-flutter