0

(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:

  1. Lock the Collection from all other clients (write OR read)
  2. Read the most recent seq_id into memory
  3. Generate 3 more sequence ids in memory (Java, in my case)
  4. Insert 3 documents into the collection
  5. 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.

Matthew Moisen
  • 16,701
  • 27
  • 128
  • 231

1 Answers1

0

MongoDB is eventually consistent which precludes both lock-based patterns as well as being guarenteed the latest update. It sounds like you should choose something like Cassandra or a standard RDBS.

Wes Widner
  • 51
  • 1
  • 4