googleapis / googleapis/google-cloud-node

Return the updated document values in the SDK response

Open
#7,478 0 comments 0 reactions 0 assignees View on GitHub
api: firestore library: nodejs-firestore priority: p3 type: feature request
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

**Is your feature request related to a problem? Please describe.**

Right now, if I am using the Node.js Firestore SDK, and I want to see what value was set when I specify `FieldValue.serverTimestamp()` as a field's value, I need to `DocumentReference.get()` the created or updated document after it has been created or updated. This is specified by the documentation for https://cloud.google.com/nodejs/docs/reference/firestore/latest/firestore/writeresult.

However, it seems like if I were to construct a REST API call using the request structure documented at https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/patch, I could use the DocumentMask to return fields with their updated/created values.

**Describe the solution you'd like**

I would like for Firestore SDK methods on `DocumentReference` to have another option property:

```
await firestore.collection('a').doc('b').update({ x: 'y' }, { returnFields: ['x'] });
```

**Describe alternatives you've considered**

I have considered using a `.get()` SDK method after using either the `.add()` or `.update()`. This seems like unnecessary added cost.

I have considered using a Node.js generated Date object as the field value but doing this would destroy the usefulness of the functionality that `FieldValue.serverTimestamp()` provides. The server timestamp is much more exact to when the document was created/updated.

**Additional context**

N/A

Thanks for your consideration!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.