gpt4 book ai didi

javascript - 使用 Firebase 和 Firestore 建立状态,部署函数 : "seconds is not a valid integer" 时出错

转载 作者:行者123 更新时间:2023-12-05 02:55:24 27 4
gpt4 key购买 nike

我正在使用 this document由 Firebase 提供,结合使用 Firebase 和 Firestore,通过使用 Firebase 的内置状态和 onDisconnect() 在 Firestore 中建立“状态”。大部分代码是 Firebase 提供的逐字记录,但我为我的数据结构定制了一些东西。我已经成功地将我的功能(如下)部署到 Firebase。检查日志,我收到此错误:

Error: Value for argument "seconds" is not a valid integer.
at Object.validateInteger (/srv/node_modules/@google-cloud/firestore/build/src/validate.js:191:19)
at new Timestamp (/srv/node_modules/@google-cloud/firestore/build/src/timestamp.js:70:20)
at Function.fromMillis (/srv/node_modules/@google-cloud/firestore/build/src/timestamp.js:126:16)
at Function.fromDate (/srv/node_modules/@google-cloud/firestore/build/src/timestamp.js:108:26)
at Serializer.encodeValue (/srv/node_modules/@google-cloud/firestore/build/src/serializer.js:97:53)
at Serializer.encodeFields (/srv/node_modules/@google-cloud/firestore/build/src/serializer.js:56:30)
at Function.fromObject (/srv/node_modules/@google-cloud/firestore/build/src/document.js:97:53)
at op (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:245:58)
at writes._ops.map.op (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:431:44)
at Array.map (<anonymous>)

由于我主要使用 Firebase 提供的代码,所以我真的不知道如何调试它。我猜这与 Firebase 和 Firestore 之间的时间戳比较有关。关于这可能出错的地方有什么建议吗?

const functions=require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp();

const firestore=admin.firestore();

exports.onUserStatusChanged=functions.database.ref('user/{uid}').onUpdate(
async (change, context) => {
const eventStatus=change.after.val();
const userStatusFirestoreRef=firestore.doc(`user/${context.params.uid}`);
const statusSnapshot=await change.after.ref.once('value');
const status=statusSnapshot.val();
console.log(status, eventStatus);

if (status.last_changed>eventStatus.last_changed){
return null;
}

eventStatus.last_changed=new Date(eventStatus.last_changed);

return userStatusFirestoreRef.set(eventStatus);
}
);

最佳答案

如果您尝试保留无效日期,也会发生此错误,例如:

new Date("string that cannot be parsed as timestamp/date")

关于javascript - 使用 Firebase 和 Firestore 建立状态,部署函数 : "seconds is not a valid integer" 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61257834/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com