通过flutter在Firestore中添加嵌套数据 [英] Add nested data in Firestore by flutter

查看:44
本文介绍了通过flutter在Firestore中添加嵌套数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自以下问题.

如何管理添加和更新数据在Firebase中

最初,我可以按照以下代码在firestore中制作数据.

Initially I can make data in firestore following code.

但是我想在 car1 之后的 cars 内添加 car2 .我不知道.

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,
        }
    }
  }

请给我建议.

推荐答案

要添加 cars2 ,然后执行以下操作:

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,
        }
    }

这篇关于通过flutter在Firestore中添加嵌套数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆