首页 > 解决方案 > 如何在 Firestore 中插入对象数组?

问题描述

在此处输入图像描述我想在 Firestore 中插入一组对象?我可以从 Firestore 控制台添加,但是从 Java 中添加它不起作用?在这里,我附上了我的控制台快照,代码是:

val map = HashMap<String, Any>()
    map["one"] = request.records
    dayFormDoc.set(map)

这里 request.records 是一个数组。

标签: javafirebasekotlingoogle-cloud-firestore

解决方案


尝试这个,

安卓

Map<String, Object> docData = new HashMap<>();

docData.put("listExample", Arrays.asList(1, 2, 3));

爪哇

ArrayList<Object> arrayExample = new ArrayList<>();
Collections.addAll(arrayExample, 5L, true, "hello");
docData.put("arrayExample", arrayExample);

更多信息https://firebase.google.com/docs/firestore/manage-data/add-data

希望能帮上忙。


推荐阅读