从 vue 客户端使用 mongoose 进行模糊搜索
Fuzzy search using mongoose from vue client
获取错误未知顶级运算符 $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"
试试这个
// 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 }
}
将 $regex 添加到 Mongoose 服务的 whitelist option:
app.use('/messages', service({
Model,
whitelist: [ '$regex' ]
}));
获取错误未知顶级运算符 $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"
试试这个
// 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 }
}
将 $regex 添加到 Mongoose 服务的 whitelist option:
app.use('/messages', service({
Model,
whitelist: [ '$regex' ]
}));