搜索栏把手+猫鼬

问题描述

当我尝试通过单词标题搜索帖子

搜索无效,并且没有帖子

我不知道语法是否正确

Post.find({'post':{title_create:wordsearching}},(err,data)=>{

但没有错误搜索后也没有结果

searchPost =输入

const Post = require('../models/PostModel').Post;
      serachPosts:async(req,res)=> {

    const wordsearching= await req.query.searchPost;

  try{
     Post.find({'post':{title_create:wordsearching}},data)=>{
          if(err){
              console.log(err);
          }else{
              res.render('default/singlePostSearch',{data:data});
          }

      })

    }catch (error) {
      console.log(error);
  }
}

和这个/models/PostModels.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const PostSchema = new Schema({
    title_create: {
        type: String,required: true
    }
});
module.exports = {Post: mongoose.model('post',PostSchema )};

解决方法

我回答的问题只删除了“发布”:

,

**您的搜索字符串应与帖子完全匹配:{tittle:String} **

 Post.find({'post.title':wordSearching},(err,data)=>{