I am having an annoying problem where req.body
does not return the full mongoose model. I'm very new to this stuff so I apologize if this is a dumb question. Here is my model:
var mongoose = require("mongoose");
var campgroundSchema = new mongoose.Schema({
name: String,
image: [String],
image_id: [String],
description: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
});
module.exports = mongoose.model("Campground", campgroundSchema);
And here is the result I receive when I console.log(req.body)
:
{ campground:
{ name: 'w',
description: 'w',
author: { id: 5aaaf25986f338289129f8ea, username: 'frff' } } }
If any more information is required please let me know.
Edit: Here is the route handler:
var imageLength;
var newImage = new Array();
router.post("/", isLoggedIn, upload.array("image"),function(req, res){
imageLength = req.files.length;
for(var i = 0; i < imageLength; i++){
cloudinary.uploader.upload(req.files[i].path, function(result) {
// add cloudinary url for the image to the campground object under image property
newImage.push(result.secure_url);
console.log(newImage[i-1]);
console.log(req.body);
req.body.campground.image.push(newImage[i-1]);
console.log(req.body);
});
}
Your sending Post request? The body is only what you are including from the client side when you make the post/put request.
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I try send my sitemapxml to Google Search Console but every time get
I am using password-hash library to hash passwords
I'm building a web crawler in nodejs and Electron
This question might be very primitive but I just started learning node stuff so please bear with meI have many console