I deployed the cloud function to Firebase and i wanna get the current server timestamp, but it return {".sv":"timestamp"}} to me.
i have check the post but seems like i using the right code: How do I get the server timestamp in Cloud Functions for Firebase?
My code:
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)
})
My API: https://us-central1-food-ninja-mobile.cloudfunctions.net/api/getUserCollectionCount?collection=users
Please advise why it will return {".sv":"timestamp"}} instead of timestamp.