RethinkDB Limit rows a user can create

28 views Asked by At

I want to limit the rows a user can create inside a table, I already tried to check the count before inserting but that wouldnt work if multiple inserts happen at the same time

Code with the earlier mentioned problem:

database.r.table('wallet').filter(function (wallet) {
return wallet('user_id').eq(123); })
.count()
.do(function (count) {
return database.r.branch(count.lt(2),
database.r.table('wallet')
.insert({ user_id: 123, wallet_name: 'My Wallet' }),
database.r.error('User has reached the maximum number of wallets')
);
}).run(database.connection)
0

There are 0 answers