字段名称不变。为什么呢? ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ........................
router.post('/bio/firstname', (req, res) => {
Habalka.findOneAndUpdate(
{_id: "d9aa8566-75fe-4108-a72e-1b67e79cf40c"},
{name: 5}
)
.then((data) => {
res.json({error: false, data: data})
});
});
模型
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);
答案 0 :(得分:0)
因此,假设路由运行正常,那么您的更新中只会出现语法错误,请尝试以下操作:
Habalka.findOneAndUpdate(
{_id: "d9aa8566-75fe-4108-a72e-1b67e79cf40c"},
{$set: {name: 5}}
)
.then((data) => {
res.json({error: false, data: data})
});