firebase / firebase/firebase-android-sdk

Firestore @Increment equivalent of FieldValue.increment()

Open
#1,449 2 comments 0 reactions 0 assignees View on GitHub
api: firestore type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

## What feature would you like to see?

When interacting with Firestore via POJOs, there are a couple of annotations available for server-derived values (`@DocumentId` and `@ServerTimestamp`). These correspond with the sentinel values you can use when storing data as `Maps<>` --` .add()` and `FieldValue.serverTimestamp()`.

There does not seem to be an annotation equivalent of `FieldValue.increment()`.

## How would you use it?

This feature would be used in the same ways as `FieldValue.increment()` but will work for developers that choose to use POJOs instead of Maps for storing data. Developers could of course do this manually, but there are potentially several places where they'd have to remember to increment the field.

The default would increment the field by 1 every time the POJO is persisted.

```
@Increment
public Long version() {
return this.version;
}
```

To have parity with the FieldValue API, you could specify how much to increment:

```
@Increment(2)
public Long version() {
return this.version;
}
```

It will also need to work with `double` fields.

If the POJO field is `null`, increment the database's version by the specified amount. The only question becomes what to do with values that are set

1. Store the value as-is without incrementing (similar to `@ServerTimestamp`)
1. Increment the value by the specified amount (would make sense for read/write cycles)

This ambiguity is also present with `@ServerTimestamp` so this isn't really a new problem -- is it a "created on" timestamp or an "updated on" timestamp; it's hard to tell.

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.