mysql - Atomic in MongoDB with transfer money -
i'm new mongodb make simple application abount account in bank.an account can transfer money others design account collection that
account { name:a age: 24 money: 100 } account { name:b age: 22 money: 300 }
assuming user transfer 100$ user b , there 2 operations : 1) decrease 100$ in user // update document 2) increase 100$ user b // update document b said atomic applied single document no mutiple document.
i have alter desgign
bank { name: address: account[ { name:a age: 22 money: ss }, { name:b age: 23 money: s1s } ] }
i have question :
- if use later way, how can write transaction query (can use findandmodify() function?) ?
- does mongodb support transaction operations mysql (innodb)?
- some pepple tell me use mysql project best way, , use mongodb save transaction information.(use collection named transaction_money save them), if use both mongodb , mysql (innodb) how can make operations below atomic (fail or success whole):
> 1) -100$ user > 2) +100$ user b > 3) save transaction
information like
transaction { sender: receiver: b money : 100 date: 05/04/2013 }
thank much.
i not sure looking for:
db.bank.update({name : "name"},{ "$inc" : {'account.0.money' : -100, 'account.1.money' : 100}})
- update() operation satisfies aci properties of ( acid ). durability ( d ) depends on mongo , application configuration while making query.
- you can prefer use findandmodify() won't yield lock on page fault
- mongodb provides transactions within document
i can't understand, if application requirement simple, why trying use mongodb. no doubt data-store, guess mysql satisfy requirements.
just fyi : there doc problem trying solve. http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/ won't recommend use because single query ( transferring money) has been turned sequence of queries.
hope helped
Comments
Post a Comment