Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore arrayUnion() silently drops server timestamp values #336

Closed
jwngr opened this issue Aug 13, 2018 · 3 comments
Closed

Firestore arrayUnion() silently drops server timestamp values #336

jwngr opened this issue Aug 13, 2018 · 3 comments

Comments

@jwngr
Copy link

jwngr commented Aug 13, 2018

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));
@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@schmidt-sebastian
Copy link
Contributor

Hey "jwngr", thanks for filing this issue. Note that we currently don't support Server Timestamps inside of Array values. It looks like we are missing some client-side validation here. We will add it shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants