when i try search post from words title
the search not work and no posts appear
i don't know if syntax is true
Post.find({'post':{title_create:wordSearching}},(err,data)=>{
but no error and also no result after searching
searchPost = input
const Post = require('../models/PostModel').Post;
serachPosts:async(req,res)=> {
const wordSearching= await req.query.searchPost;
try{
Post.find({'post':{title_create:wordSearching}},(err,data)=>{
if(err){
console.log(err);
}else{
res.render('default/singlePostSearch',{data:data});
}
})
}catch (error) {
console.log(error);
}
}
and this /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 )};
我回答这个问题只删除“帖子”:
**您的搜索字符串应与帖子完全匹配:{标题:字符串} **
Post.find({'post.title':wordSearching},(err,data)=>{
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.