I'm getting error for using admin.firestore.FieldValue.serverTimestamp inside transaction.create.
The same is working in a previous deployed different functions. But this is not working this functions deployed now.
Here is my sample code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
//...
exports.monthlyReports = functions.firestore.document('transactions/{transactionId}').onWrite((snap, context) => {
return firestore.runTransaction(transaction => {
return transaction.get(reportsRef).then(doc => {
//....
transaction.create(eventIdRef, { s: admin.firestore.FieldValue.serverTimestamp } );
//...
return Promise.resolve();
});
});
});
I'm getting the following error:
Error: Cannot encode value: serverTimestamp() {
return ServerTimestampTransform.SERVER_TIMESTAMP_SENTINEL;
}
at Serializer.encodeValue (/srv/node_modules/@google-cloud/firestore/build/src/serializer.js:160:15)
at Serializer.encodeFields (/srv/node_modules/@google-cloud/firestore/build/src/serializer.js:65:34)
at Function.fromObject (/srv/node_modules/@google-cloud/firestore/build/src/document.js:93:53)
at op (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:147:58)
at writes._ops.map.op (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:429:44)
at Array.map (<anonymous>)
at WriteBatch.commit_ (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:429:34)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
serverTimestamp is a function and should be invoked. Your code is passing it as a value. See https://googleapis.dev/nodejs/firestore/latest/FieldValue.html#.serverTimestamp
Most helpful comment
serverTimestampis a function and should be invoked. Your code is passing it as a value. See https://googleapis.dev/nodejs/firestore/latest/FieldValue.html#.serverTimestamp