使用来自vue客户端的mongoose进行模糊搜索

问题描述 投票:1回答:2

获取错误未知的顶级操作员$ 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”

vue.js mongoose fuzzy-search feathersjs
2个回答
3
投票

将$ regex添加到Mongoose服务的whitelist option

app.use('/messages', service({
  Model,
  whitelist: [ '$regex' ]
}));

3
投票

试试这个

// 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 }
    }
© www.soinside.com 2019 - 2024. All rights reserved.