我有一个对象数组;示例:listOfExpenses = [{...}, {...}, {...}]
,当前它是一个空数组,我想向该数组添加一个对象。
我这样称呼:
const chatInstance = db.collection("chats").doc("1234567");
chatInstance.update({
listOfExpenses: admin.firestore.FieldValue.arrayUnion({
amount: 10,
category: "food",
date: "2019-06-16T07:25:26.010Z"
})
});
这是我得到的错误
FirebaseError: Function DocumentReference.update() called with invalid data. Unsupported field value: a custom object (found in field listOfExpenses)
at new FirestoreError (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:355:28)
at ParseContext.createError (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19726:16)
at validatePlainObject (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:20111:27)
at UserDataConverter.parseData (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19912:13)
at /Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19835:41
at forEach (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:457:13)
at UserDataConverter.parseUpdateData (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19826:9)
at DocumentReference.update (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:20732:52)
at bot.command.ctx (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/index.js:127:22)
at Promise.resolve.then (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/telegraf/composer.js:128:56)
Failed to process updates. { FirebaseError: Function DocumentReference.update() called with invalid data. Unsupported field value: a custom object (found in field listOfExpenses)
at new FirestoreError (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:355:28)
at ParseContext.createError (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19726:16)
at validatePlainObject (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:20111:27)
at UserDataConverter.parseData (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19912:13)
at /Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19835:41
at forEach (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:457:13)
at UserDataConverter.parseUpdateData (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:19826:9)
at DocumentReference.update (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/@firebase/firestore/dist/index.node.cjs.js:20732:52)
at bot.command.ctx (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/index.js:127:22)
at Promise.resolve.then (/Users/edvinsantonovs/Documents/repos/dollar-dollar-bot/node_modules/telegraf/composer.js:128:56)
code: 'invalid-argument',
name: 'FirebaseError',
toString: [Function] }
我不太确定自己在做什么错
答案 0 :(得分:0)
当我遇到相同的错误时,这是因为我的firebase管理SDK admin
实例与我用来获取firestore()
实例的实例不同。您可能想尝试将示例代码段中的db
替换为admin.firestore()
,以确保您的情况并非如此