firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

No event.data returned onDocumentWritten

Open Georg7 opened this issue 1 year ago • 0 comments

Related issues

No

[REQUIRED] Version info

node:

v18.12.0

firebase-functions: 5.0.1

firebase-tools:

13.11.4

firebase-admin: 11.8.0

[REQUIRED] Test case

const logger = require("firebase-functions/logger");
const { onDocumentWritten, Change, FirestoreEvent } = require("firebase-functions/v2/firestore");

exports.userChanges = onDocumentWritten("users/{uid}", async (event) => {
	logger.info("uid", event.params.uid);
        logger.info("snap", event.data.after);
	logger.info("after", event.data.after.data());

	return;
})

[REQUIRED] Steps to reproduce

Deploy the above function and inspect event.data.after.data() and event.data.after.data()

Note:

  • Function triggers correctly
  • Event params are accessible
  • Document snapshot is available
  • calling .data() on the document snapshot does NOT return the data (empty)

[REQUIRED] Expected behavior

Access the document data before and after the document was written to

[REQUIRED] Actual behavior

Log from console: 2024-07-02 20:54:37.493 SGT uid 1234567890 2024-07-02 20:54:37.494 SGT snap QueryDocumentSnapshot { _fieldsProto: { .... 2024-07-02 20:54:37.496 SGT after

same result behavior for event.data.before.data()

Were you able to successfully deploy your functions?

Yes, function deploys correctly.

Georg7 avatar Jul 02 '24 13:07 Georg7