【发布时间】:2020-05-10 00:59:04
【问题描述】:
字段名称不会改变。为什么 ? ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ......................
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);
【问题讨论】:
-
不要在您的帖子中添加点垃圾邮件文本来绕过要求您解释更多问题的要求 - 相反,请更详细地实际解释问题,例如您尝试过的哪种调试不起作用。查找如何创建 minimal reproducible example 也可能会有所帮助 - 考虑删除与问题不直接相关的代码。
-
我应该写什么?从标题已经很清楚我需要什么了,我不知道该写什么
-
除了垃圾文本之外的任何内容都更可取 - 您可以详细说明更多问题,以及您尝试了哪种调试方式,等等。
-
我当然可以写点别的,但这只会因为写更多不必要的信息而使问题复杂化
-
请描述预期的行为。您只需显示示例数据和代码。您还应该包括当前行为和您的期望。此外,您还没有在架构中定义
name,但您想更新它。它将在验证期间被删除。
标签: node.js mongodb express mongoose