我第一次使用rethinkdbdash t,我试图简单地创建一个用户,但如果它存在,则错误退出。从我所读到的所有文档中,下面的代码应该可以工作,但是当我不止一次运行它时,它一直在插入,从未真正检测到冲突。我是不是做错了?
r.table("users").insert({
"username": "blahblah"
},
conflict="error"
).run().then(function(response) {
console.log('Success ', response);
})
.error(function(err) {
console.log('ERROR occurred ', err);
})发布于 2018-03-14 13:38:25
我已经想明白了。我错过了很大一部分文档。冲突方法查看主键。在这种情况下,它是"id“。“用户名”是一个通用名称。
工作守则是:
r.table("users").insert({
"id": "blahblah"
},
conflict = "error"
).run().then(function(response) {
console.log('SUCCESS: ', response);
}).error(function(err) {
console.log('ERROR: ', err);
});https://stackoverflow.com/questions/49278783
复制相似问题