我正在尝试使用Thinky 检查表中的一个字段是否存在(区分大小写)。如果没有Thinky,我可以使用RethinkDB简单的筛选器-match操作来匹配字段:
// This makes my variable insensitive.
let myFieldInsensitive = '(?i)^' +myFieldSensitive`enter code here`+'$';
// Filter by matching myFieldInsensistive.
r.table('myTable').filter(r.row('myField').match(myFieldInsensitive))
.run(myConnection, function (err, result) {
console.log(result.length); // returns 1 if myFieldInsesitive was found
})此代码将检查mySpecificField是否存在于myTable (区分大小写)中。
现在,我尝试使用Thinky执行相同的匹配,但是ORM不支持这种语法:
let myFieldInsensitive = '(?i)^' +myFieldSensitive+'$';
myModel.filter(('myField').match(myFieldInsensitive)})
.run().then((result) => {
console.log(result.length); // should return 1 if myFieldInsesitive was found, but this returns always empty array
})有人知道如何使用Thinky在表中匹配数据吗?
发布于 2016-03-05 15:36:00
终于成功了!我包括了thinky.r:
let r = thinky.r;
而不是写作
myModel.filter(('myField').match(myFieldInsensitive))
我写
myModel.filter(r.row('myField').match(myFieldInsensitive))
,瞧,!
https://stackoverflow.com/questions/35798071
复制相似问题