【发布时间】:2018-03-29 21:59:39
【问题描述】:
我是node.js 和mongodb 的完整初学者,所以如果我的问题看起来很愚蠢,请原谅。基本上我正在尝试使用where 和or 运算符执行以下操作从this question 得到一些精炼的结果,但它显示错误。
代码:
//here "data" is the emitted socket object from client side
var string = data.search.replace(/[\/\\#@+()$~%'":*?<>{}]/g, '')
var regex = new RegExp(["^", string].join(""), "i");
db.collection("user_information").find()
.where('_id').ne(data.userId)
.or([
{email: regex},
{fullname:regex}
])
.select('fullname email')
.exec(function(err, res){
console.log(res)
})
错误:
TypeError: db.collection(...).find(...).where is not a function
at C:\chat\mongo.js:1898:14
at connectCallback (C:\Users\Srinu\AppData\Roaming\npm\node_modules\mongodb\lib\mongo_client.js:515:5)
at C:\Users\Srinu\AppData\Roaming\npm\node_modules\mongodb\lib\mongo_client.js:430:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
【问题讨论】: