【问题标题】:how to make a search in node using mongoose based on keywords如何使用基于关键字的猫鼬在节点中进行搜索
【发布时间】:2020-05-14 14:20:43
【问题描述】:

const UserSchema = new mongoose.Schema({ 名称:字符串, 项目名称:字符串 });

const User = new mongoose.model("User", UserSchema);

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Search</title>
  </head>
  <body>
      <form  action="/" method="post">
          <input type="text" name="txt">
          <button type="submit" name="button" >Search</button>
      </form>
  </body>
</html>

我希望如果项目名称是“机器学习和 oops”,并且我在搜索框中搜索“oops”,我应该会显示“机器学习和 oops”

【问题讨论】:

标签: node.js mongodb mongoose


【解决方案1】:

您可以像这样使用正则表达式模式进行fuzzy 搜索。

User.find({project_name : /your-search-keyword-variable-here/}) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2019-09-06
    • 2021-09-19
    相关资源
    最近更新 更多