Skip to content

Firestore arrayUnion() silently drops server timestamp values #336

@jwngr

Description

@jwngr

Environment

  • Operating System version: All
  • Firebase SDK version: 6.0.0
  • Firebase Product: Firestore

Problem

Thanks for adding the new admin.firestore.FieldValue.arrayUnion() and admin.firestore.FieldValue.arrayRemove() features. They're super handy! I think I found a bug in it though. When you try to add an item which contains admin.firestore.FieldValue.serverTimestamp() via admin.firestore.FieldValue.arrayUnion(), the timestamp is never set and the corresponding field is dropped.

Steps to reproduce:

  1. Run the repro below.

Expected result:

The database should look like this:

screen shot 2018-08-12 at 10 34 29 pm

Actual result:

The database ends up looking like this:

screen shot 2018-08-12 at 10 33 52 pm

If you switch the non-working admin.firestore.FieldValue.serverTimestamp() with new Date(), the expected result occurs.

Relevant Code:

return admin.firestore().doc('items/2').set({
  someArray: admin.firestore.FieldValue.arrayUnion({
    createdAt: admin.firestore.FieldValue.serverTimestamp(),
    foo: 'bar',
  }),
})
  .then(() => console.log('Success!'))
  .catch((error) => console.log('Error:', error));

Note that this also fails, resulting an an empty someArray array:

return admin.firestore().doc('items/2').set({
  someArray: admin.firestore.FieldValue.arrayUnion(
    admin.firestore.FieldValue.serverTimestamp()
  ),
})
  .then(() => console.log('Success!'))
  .catch((error) => console.log('Error:', error));

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions