繁体   English   中英

firebase-admin:FieldValue.arrayUnion 不工作 NodeJS

[英]firebase-admin: FieldValue.arrayUnion not working NodeJS

我正在使用 firebase-admin v11.2.1

我可以使用以下方法更新项目中的标题:

if (title) {
  batch.update(projectRef, {
    title
  })
}

但是我不能使用以下方法将项目添加到数组:


batch.update(projectRef, {
   admins: admin.firestore.FieldValue.arrayUnion(`/users/${admin}`)
})

错误在 catch 块中被捕获,但错误返回为空 object

} catch (err) {
    res.status(500).json({ error: err })
}

解析为:

{
    "error": {}
}

我读到的所有我想做的事情都指向 arrayUnion 作为答案,但它对我不起作用。 任何帮助表示赞赏 - 谢谢。

编辑:这是项目建模的方式。

在此处输入图像描述

我也在另一个代码库上,其中 arrayUnion 不起作用。 我收到错误:


const ids = members.map((member) => member.id);

await projectRef.update({
   members: admin.firestore.FieldValue.arrayUnion(...ids)
)}

error TypeError: Cannot read properties of undefined (reading 'arrayUnion')

尽管我在另一个代码库中,其中 arrayUnion 的工作方式与您预期的完全一样(firebase-admin 版本 9.8):

 if (role === 'admin') {
    batch.update(organisationRef, {
      invitedAdmins: admin.firestore.FieldValue.arrayUnion(userId)
  })
}

非常难过

const { FieldValue } = require('firebase-admin/firestore');

FieldValue.arrayUnion(userId)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM