Sunday, 28 May 2017

How do I change this "schema" with out the need of transactions(ACID)?

I have a model like the following one in MongoDB using Mongoose:

Stuff
{
_id: ObjectId...,
stuff: String..,
someBoolean: Boolean,
description: String,
transactionsOfThisStuff: [{
  trnsactionNumber: objectId?
  date: Date.now()
  info: String
 }]
}

As you can see, the idea is to move stuff, and I need to register every movement, so I made an array of "transactions" where I keep the history.

To make a "transaction" there are some requirements, for example, the "someBoolean" must be in certain value, etc. And when a transaction is made, some values of the stuff must be updated.

Also, I must be able to move multiple stuff at the same time (move a table, a plumbus, etc), so all of them will have the same "transactionNumber" in each document.

The problem I see with this model is that I can't easily for example list the last 10 movements, or I don't find efficietn getting the Stuff that has been moved with a given "transactionNumber".

If a use two models:

Stuff
{
      _id: ObjectId...,
      stuff: String..,
      someBoolean: Boolean,
      description: String,
}

transaction
{
     _id: objectId,
     date: Date.now(),
     info: String,
     stuff: [{type:ObjectId, ref: 'Stuff', requiered: true}]
}

the problem with this idea, is that I would need ACID, since if move multiple Stuff, I need to update some values in the "Stuff" :/



via Mariano Zunino

No comments:

Post a Comment