获取错误未知的顶级操作员$ regex
search.view`
let questDocuments = await conversation
.find({ query: { $limit: 100, $search: q, skippop: true } })
.then(response => {`
q是传递的字符串
服务钩
before: {
all: [],
find: [
hookBeforeFind,
search({
fields: ["label"],
deep: true
})
],
模型
const conversation = new Schema(
{
label: { type: String, required: true },
nodeId: { type: String, required: true },
details: { type: String },
url: { type: String },
creator: { type: String },
handle: { type: String },
date: { type: String },
从搜索栏添加表达式进行搜索。例如“the”
将$ regex添加到Mongoose服务的whitelist option:
app.use('/messages', service({
Model,
whitelist: [ '$regex' ]
}));
试试这个
// regex to find records that start with letter any name , example "e"
Model.aggregate([
{
$match: {
field_name: {
$regex: "^" + searchName,
$options: "i"
}
}
}]).exec(function(err, result) {
if (err) { // handle here }
if (result) { // do something }
}