ES6 Mongo /猫鼬不起作用

时间:2018-07-13 02:36:31

标签: javascript mongodb

我正在使用axios向我的put发送一个API请求,这就是axios调用的外观:

  

index.jsx

.put(`${helper.baseURL}/user/edit-userType/${ids}`, body, {
  headers: { Authorization: header }
})

body可以是这两个对象{ banned: true }{ userType: "publisher"}

之一

在后端完美接收对象,这是其中的两个,这是API

  

user.js

router.put(
  `${prefix}/edit-userType/:id`,
  tokenController.ensureToken,
  (req, res) => {
    let body = req.body;
    let ids = req.params.id.split(",");
    let newDate = new Date();
    body.updatedAt = newDate;
    console.log("body", body); <<<< This returns { banned: false, updatedAt: 2018-07-13T02:29:30.619Z } OR { userType: "publisher", updatedAt: 2018-07-13T02:29:30.619Z }
    modelUser.update(
      {
        _id: {
          $in: ids
        }
      },
      {
        $set: {
          body  <<<<< this is not updating my user :(
        }
      },
      (err, user) => {
       Stuff...
      }
    );
  }
);

我不知道为什么body与用户架构具有相同的key: value而不更新。

  

userSchema.js

const userSchema = new Schema({
  a lot of: boring stuff,
  userType: { type: String, default: "regular" },
  banned: { type: Boolean, default: false },
  boring stuff: again
})

0 个答案:

没有答案