获取错误未知的顶级运算符$ regex
search.vue`
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”
答案 0 :(得分:3)
在$ Mongoose服务的whitelist option中添加$ regex:
app.use('/messages', service({
Model,
whitelist: [ '$regex' ]
}));
答案 1 :(得分:2)
尝试
// 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 }
}