Auto-increment 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.