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?
All of the requirements cannot be satisfied client-side when using multiple clients, some of which might be off-line.
Here is a process that results in a monotonically-increasing id:
The database will have double the number of records, so it will grow more quickly and need to be compacted sooner if space is an issue. Any views/queries on the employee records will need to check for the permanent flag, in case a query runs while the external process is adding a new record.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With