【问题标题】:Flutter : How to add element to map field inside firebase database?Flutter:如何将元素添加到 Firebase 数据库中的映射字段?
【发布时间】:2020-12-05 17:48:06
【问题描述】:

我正在尝试从我的颤振代码中找到一种将元素添加到 firebase 数据库内的映射字段的方法。该元素也是一个地图。所以它是一个嵌套的地图。

 Future updateImageDate({
        String token,
        int rating,
        int like,
        int display_count,
        //Map participants,
      }) async {
        return await pictureCollection.document(token).updateData({
          'rating': rating,
          'like': like,
          'display_count': display_count,
          //'participants': participants, 
         // I want to add only one element to this existing map field in firebase database.
         // Although currently it's empty, I want to keep add new element every time I use this method.
        // The element as well is a map. So it's a nested map.
         
        });
      }

请帮帮我!我期待着您的回音。先感谢您。 :D

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    要写入地图,请使用点 (.) 表示法。所以:

    pictureCollection.document(token).updateData({ 'path.to.field': 'new value' });
    

    【讨论】:

    • 这是不是因为.的特殊含义而必须使用FieldPath的情况之一?
    • 我不这么认为。它似乎只是一个嵌套字段,因此使用点来解决字段名称。
    • 我决定将一堆地图嵌套在一个列表中
    猜你喜欢
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2019-08-23
    • 2022-08-18
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    相关资源
    最近更新 更多