Add nested data in Firestore by flutter

倖福魔咒の 提交于 2021-02-17 06:30:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!