搜索栏车把 + 猫鼬
search bar handlebars + mongoose
当我尝试从单词标题
中搜索post时
搜索无效,没有 post 出现
我不知道语法是否正确
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}},(err,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 )};
我回答问题只删'post':
**您的搜索字符串应与 post:{tittle:String} 完全匹配 **
Post.find({'post.title':wordSearching},(err,data)=>{
当我尝试从单词标题
中搜索post时搜索无效,没有 post 出现
我不知道语法是否正确
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}},(err,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 )};
我回答问题只删'post':
**您的搜索字符串应与 post:{tittle:String} 完全匹配 **
Post.find({'post.title':wordSearching},(err,data)=>{