Auto-increment ID

In my project, I have added an initial value to ID through java application.
Now, i want to auto-increment this ID value every time the program runs.

This one is tough because this there is no concept of tables and rows. So there is no “last row” to increment from. If your SET()/sec is not really high then you could do a view to get the last document “887_your_key”… then you next would would be “888_your_key”…
How many SET()/sec will you be doing at Peak?

Number of SET()/sec will increase in future…so I want a robust workaround to auto increment view ID.

the general pattern for auto increment is:

  1. use the incr() operation to atomically create a new number (a specific doc which acts as your counter)
  2. then go use that number to construct the document key.

This will make sure that - since the incr is atomic - you will not end up with duplicate keys.