(The other questions on the side bar with similar titles do not address this issue.)
I have a collection that I use like a historical sequence generator:
{seq_id:1,dt:ISODate(...),type:'service_a',stage:1}
{seq_id:2,dt:ISODate(...),type:'service_a',stage:2}
{seq_id:3,dt:ISODate(...),type:'service_a',stage:3}
{seq_id:1,dt:ISODate(...),type:'service_b',stage:1}
{seq_id:2,dt:ISODate(...),type:'service_b',stage:2}
{seq_id:3,dt:ISODate(...),type:'service_b',stage:3}
I want to be able to:
- Lock the Collection from all other clients (write OR read)
- Read the most recent seq_id into memory
- Generate 3 more sequence ids in memory (Java, in my case)
- Insert 3 documents into the collection
- Unlock the collection
I want to be able to lock all other clients from even reading the collection while my client has it locked, as another client that reaches step 2 and 3 before my client reaches step 4 would result in conflicting seq_ids.