我想保存到猫鼬列表的开头

时间:2018-12-06 11:26:12

标签: 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!"
      });
    });
};

0 个答案:

没有答案