我将云函数部署到Firebase,并想要获取当前服务器时间戳,但它返回给我{".sv":"timestamp"}}。
我查看了帖子,但似乎我正在使用正确的代码: 如何在Firebase云函数中获取服务器时间戳?
我的代码:
var firebase = require('firebase-admin');
var serviceAccount = require('./privateKey/key.json');
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://food-ninja-mobile.firebaseio.com/'
});
db = firebase.database();
db.ref(collection).once('value', snap => {
var snapVal = snap.val()
var myData = Object.keys(snapVal).map(key => {
return snapVal[key];
})
var snapLength = myData.length
returnMsg = {}
returnMsg['DbCollection'] = collection
returnMsg['count'] = snapLength
returnMsg['action'] = 'getUserCollectionCount'
returnMsg['timeStamp'] = firebase.database.ServerValue.TIMESTAMP
console.log(returnMsg)
return res.status(200).send(returnMsg)
})
我的 API: https://us-central1-food-ninja-mobile.cloudfunctions.net/api/getUserCollectionCount?collection=users 请问为什么它会返回 {".sv":"timestamp"} 而不是 timestamp。