如何将数组传递给firebase firestore arrayUnion() 函数?
尝试传递数组时出现此错误。
错误
Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
例
let myArray = ["1", "2", "3"];
docRef.update({
test: firebase.firestore.FieldValue.arrayUnion(myArray)
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Node.js Firebase Admin SDK 将新的 javascript 对象添加到 Firestore 集合中的数组字段。
我确信我所针对的文档具有相关字段,但我不断收到错误:TypeError:
Cannot read property 'arrayUnion' of undefined
我知道这个问题,但修复没有帮助。
非常感激任何的帮助。
有问题的路线:
router.post("/create-new-user-group", async (req, res) => {
try {
const { userId, usersName, groupName } = req.body;
if (!userId || !usersName || !groupName) return res.status(422).send();
const groupRef = await db.collection("groups").doc();
const group = await groupRef.set({
id: groupRef.id,
name: groupName,
userId,
members: [{ id: userId, name: usersName, isAdmin: true }],
});
const response = await db
.collection("users")
.doc(userId)
.update({
groups: …Run Code Online (Sandbox Code Playgroud)