node.js - Express 会话属性未在架构中设置
问题描述
我正在尝试使用express-session
属性在 Mongoose 文档中设置值,但是每当我这样做时,它都会返回“ownerId
需要路径”。
在创建猫鼬模型之前和之后,我都尝试将变量记录到控制台。
router.post('/create', (req, res) => {
console.group();
var propertyId = randomString(11);
var ownerId = req.session.userId;
console.log("ownerId value: " + ownerId);
var newProperty = new Property({
_id: propertyId,
owner: ownerId,
address: req.body.address,
landline: req.body.landline
});
console.log("ownerId value: " + ownerId);
Property.create(newProperty, (err, property) => {
if (err) {
res.send(err);
} else {
res.send(property);
}
});
console.groupEnd();
});
我希望两者都console.log
输出 ID,他们确实这样做了,但我也希望newUser
对象包含 ID,但由于我在Property.save
函数上遇到验证器错误,我知道它没有。
解决方案
Path ownerId is required
信息
这意味着在您的表模式(Property
方案)中定义了一个名为 -的字段ownerId
,但是当您创建一个新的 时Property
,输入数据不包括ownerId
字段。
我看到您的输入数据包括owner: ownerId,
,只需再次检查您的表架构。
推荐阅读
- android - Android studio firebase 如何下载和显示图像(无需先上传!)
- r - 取决于其他列值的选定行的中位数
- c# - 尝试捕获和线程中的索引更改
- javascript - Uncaught TypeError: Object(...) is not a function when bundled with WebPack 4
- python - 将 SciPy 优化限制为整数
- aem - 如何在使用条件语句的同时附加一个字符?
- javascript - 用 JS 计算一个值并将该值存储在数据库中
- react-native - 当我们平移本机反应时,如何检测对象的 x 位置?
- javascript - React - 尝试在 reduce() 函数中引用 this.props
- biztalk - BizTalk Server TMS 警告 12223