我正在尝试将一个元素添加到firestore中的一个数组中,如果该数组存在;否则,我需要创建该数组,然后将该元素添加到其中。
await workoutDoc
.collection("exercises")
.doc(exerciseId)
.update({"sets": FieldValue.arrayUnion(sets)});如果我必须更新现有的数组,这段代码可以很好地工作;如果不存在数组,我该如何创建?
尝试使用merge - true和false。
await workoutDoc
.collection("exercises")
.doc(exerciseId)
.set(exercise, SetOptions(merge: true));这只是替换了数组元素。
发布于 2021-12-03 08:01:40
将这两者结合起来:
await workoutDoc
.collection("exercises")
.doc(exerciseId)
.set("sets": FieldValue.arrayUnion(<new element>), SetOptions(merge: true));https://stackoverflow.com/questions/70210911
复制相似问题