ES6 Mongo/Mongoose does not work

By | July 14, 2018
Questions:

I’m using axios to send a put request to my API, this is how it looks the axios call:

index.jsx

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

body could be one of this two objects { banned: true } or { userType: "publisher"}

on the back-end receive the object perfectly, one of these two, here’s looks the 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...
      }
    );
  }
);

I dont know why if body have the same key: value as the user schema it does not update.

userSchema.js

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

Leave a Reply

Your email address will not be published. Required fields are marked *