Я хочу сохранить в начале списка в Mongoose, а не "нажать", как делает команда Сохранить.Буду рад помочь, спасибо!
Мой код
exports.createPost = (req, res, next) => {
const url = req.protocol + "://" + req.get("host");
const post = new Post({
title: req.body.title,
content: req.body.content,
imagePath: url + "/images/" + req.file.filename,
creator: req.userData.userId,
fullName: req.userData.fullName
});
post
.save()
.then(createdPost => {
res.status(201).json({
message: "Post added successfully",
post: {
...createdPost,
id: createdPost._id,
},
fullName: req.userData.fullName
});
})
.catch(error => {
res.status(500).json({
message: "Creating a post failed!"
});
});
};