Im trying to create a new document in firestore using a cloud function. However i am unable to save the date as a timestamp rather, it's saved as a string currently.
How it is right now
What i need to achieve
Snippet of my cloud function
await admin.firestore()
.doc('/buyerProfile/' response.buyerId)
.collection('notifications')
.add({
'type':'New response',
'responseId':response.responseId,
'requestId':response.requestId,
'date': Date(Date.now()),
'compressedImgUrl':response.compressedImgUrl,
'description':response.description,
'requestPaidFor':request.data().isPaidFor
}).then(()=>console.log('Notification created'));
CodePudding user response:
You can use to get timestamp new Date().getTime();
You can also use serverTimestamp()
method instead:
date: admin.firestore.FieldValue.serverTimestamp()
CodePudding user response:
This worked for my case, i had to import Timestamp from firebase admin
const { timeStamp, time } = require("console");
...
'date': timeStamp.now(),