I'm very new to couchdb and I'm wondering how I can create ID's that look like.
Employee:DBX-**0001**-SP
the number portion 0001 must be unique and sequential. How can I achieve something like this in couchdb? I searched all over and I cannot find any simple solution.
It would be best if I can generate the sequential portion in couchdb and not on the client side to avoid collisions during replication.
The current solution I have is that I fetch a document I've stored that looks like this {"_id": "EmployeeAutoIncrement", value: 1} upon retrieval I increment the value and send it back to the server if those are successful then I return the new incremented value and use it as my Auto Increment Value to be part of the ID Employee:DBX-AUTO_INCREMENT_VALUE_HERE-SP
The issue with this is that if two people make a request to the EmployeeAutoIncrement at the same time and they both update it will it not cause conflicts? Also, if one person makes a request and they go offline then they come back online then wouldn't that also make a conflict?
JSON.stringify(new Date())
as the auto increment. It's unique, sequential and as a bonus stores the date created. I'm not sure how this can be done on the server side so there could be an issue with multiple clients trying to create a document at the same millisecond. You could retry once if it fails due to the _id already existing and that should account for most cases.