【发布时间】:2018-06-05 07:53:08
【问题描述】:
之前,我的代码运行良好,并从 firestore 返回 Long 时间戳值。自 firestore 1.0 发布以来,代码返回 [object Object] 作为结果。尽管它将时间戳保存为June 5, 2018 at 10:38:44 AM UTC+3,这意味着它当前未在firestore 数据库中保存为long 值。我从昨晚开始尝试了一些可能的解决方案,但没有奏效。有什么解决办法吗?
exports.get_time = functions.https.onRequest((request, response) => {
// if (!request.headers.authorization) {
// console.error('No Firebase ID token was passed');
// response.status(403).send('Unauthorized');
// return;
// }
var fieldValue = require("firebase-admin").firestore.FieldValue;
db.collection('times').doc('servertime').set({servertime: fieldValue.serverTimestamp()}).then((ref) => {
db.collection('times').doc('servertime').get().then((snapshot) => {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(String(snapshot.data()));
response.end();
return null;
}).catch((error) => {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Error\n" + error);
response.end();
});
return null;
}).catch((error) => {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Error\n" + error);
response.end();
});
});
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions