I am trying to turn a static website to dynamic website. For that I am using express-hbs. I req for 3 thing, here they are.
const PostSchema = new mongoose.Schema ({
title: {type: String, require: true},
content: {type: String, rqeuire: true},
date: { type: Date, default: Date.now}
})
And here is my hbs code,
<div class="row">
{{#each posts}}
<div class="col-md-6">
<div class="blog">
<div class="blog-img">
<img src="img/blog2.jpg" class="img-fluid">
</div>
<div class="blog-content">
<ul class="blog-meta">
<li><i class="fas fa-users"></i><span class="writer">{{title}}</span></li>
<li><i class="fas fa-clock"></i><span class="writer">{{date}}</span></li>
<li><i class="fas fa-comments"></i><span class="writer">13</span></li>
</ul>
<h3>{{title}}</h3>
<p>{{content}}</p>
<a href="blog-single.html">Read More</a>
</div>
</div>
</div>
{{/each}}
And my router code;
router.post("/test" , (req,res) => {
Post.create(req.body)
res.redirect("/")
})
But to my mongoDB Compass, only date is coming. Title and content actually came to my database for one time, but when i post another title and content, nothing came. Only date.
You have a misspelling in your Mongoose schema. To require a field use
required, not "require" (or "rqeuire").