RethinkDB 限制用户可以创建的行

问题描述 投票:0回答:0

我想限制用户可以在表中创建的行,我已经尝试在插入之前检查计数但是如果同时发生多个插入则行不通

前面提到的问题的代码:

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)
rethinkdb reql
© www.soinside.com 2019 - 2024. All rights reserved.