findOneAndUpdate don't update field name

The following is an example of a situation where the user is not allowed to change the field name.

enter image description here

router.post('/bio/firstname', (req, res) => {

  Habalka.findOneAndUpdate(
    {_id: "d9aa8566-75fe-4108-a72e-1b67e79cf40c"},
    {name: 5}
  )
    .then((data) => {
      res.json({error: false, data: data})
    });

});

model

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const HabalkaSchema = new Schema({
  _id: {
    type: String
  },
  bio: {
    firstname: {},
    lastname: {},
    middlename: {},
    company: {}
  },
  rating: [

  ],
  files: [
    {
      _id: {
        type: String
      },
      destination: {
        type: String
      },
      filename: {
        type: String
      },
      path: {
        type: String
      },
      folder: {
        type: String
      },
      info: {
        size: {
          type: Number
        },
        mimetype: {
          type: String
        },
        encoding: {
          type: String
        },
        originalname: {
          type: String
        },
        fieldname: {
          type: String
        },
      },
      date: {
        type: Date,
        default: Date.now
      },
      bio: {
        type: Object
      },
      userId: String,
      guessId: {},
    }
  ],
  date: {
    type: Date,
    default: Date.now
  }
});
module.exports = Habalka = mongoose.model('habalka', HabalkaSchema);

解决方案:

So assuming the route works fine you just have a syntax error in your update, try this:


  Habalka.findOneAndUpdate(
    {_id: "d9aa8566-75fe-4108-a72e-1b67e79cf40c"},
    {$set: {name: 5}}
  )
    .then((data) => {
      res.json({error: false, data: data})
    });


本文来自投稿,不代表实战宝典立场,如若转载,请注明出处:https://www.shizhanbaodian.com/40384.html

(0)
上一篇 20小时前
下一篇 20小时前

相关推荐

发表评论

登录后才能评论