【问题标题】:Fuzzy search using mongoose from vue client使用来自 vue 客户端的猫鼬进行模糊搜索
【发布时间】:2019-02-13 18:21:46
【问题描述】:

得到错误未知的顶级运算符 $regex

搜索.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 },

从搜索栏中添加表达式进行搜索。例如“那个”

【问题讨论】:

    标签: vue.js mongoose fuzzy-search feathersjs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案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 }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-20
        • 1970-01-01
        • 2019-04-22
        • 1970-01-01
        相关资源
        最近更新 更多