node.js - 修改架构后,猫鼬查询挂起
问题描述
我修改了我的架构,现在只要 mongoose 尝试运行查询,它就会挂起。更糟糕的是,我将架构恢复正常,但它仍然挂起。我需要杀死一些后台进程吗?将代码放在下面,但正如我所说,这以前有效。换了再放回去还是坏了。这是所有查询,而不仅仅是这个。
routes.route('/userInfo/:username')
.get(async (req, res) => {
res.send(await userModel.findOne(
{username:req.params.username}).lean().exec());
})
模型设置
var mongoose = require('mongoose'),
modelName = 'user',
schemaDefinition = require('../schema/' + modelName),
schemaInstance = mongoose.Schema(schemaDefinition),
modelInstance = mongoose.model(modelName, schemaInstance);
module.exports = modelInstance
架构
module.exports = {
username: String,
email: String,
firstName: String,
lastName: String,
createdOn: Date,
updatedOn: Date,
scopes: [String]
}
更新:我删除了整个项目并从 github 重新克隆了它。它开始工作了......哇。我之前尝试过删除 node_modules 。我重新启动了我的电脑。这些都没有奏效。为什么废话确实删除了项目工作:(
我不确定这是否重要,但我的模型来自我从 github 存储库中提取的一个 npm 模块(我在几个不同的项目中共享它)。
解决方案
让我们首先确认一下,确保路线确实被击中,并确保没有错误:
routes.route('/userInfo/:username').get((req, res) => {
console.log(req.params);
userModel.findOne({
username: req.params.username
}).lean().exec().then(data => {
console.log(data);
res.send(data);
}, err => {
console.log(err);
res.status(500).send({ message: 'An error occurred' });
});
});
我只知道 Express,我不熟悉您在这里使用的任何路由库,但除非其他人另有说明,否则我会假设您做的那部分是正确的。
让我知道这给了你什么。
推荐阅读
- ios - Xamarin.iOS。上诉。由于 Appodeal 插件中的旧 Yandex SDK,App Store 拒绝了应用
- c# - 无法读出我通过 ItemsEvents_ItemAddEventHandler 获得的项目
- php - 如何在 CodeIgniter 中使用自己的电子邮件库通过电子邮件库发送附件
- ansible - 如何在 Ansible 中默认从“全部”中排除库存组?
- javascript - 展平数组内部的数组
- sql-server - 如果 GetDate() 等于特定日期,则设置文本
- node-red - 节点红色显示不同仪表中的不同键值来自相同的有效载荷
- javascript - 如何在数组中查找缺失的数字
- c# - 为每个子目录创建一个 7zip 文件,从 winforms 中的输入路径到输出路径
- javascript - 如何更新处于反应状态的对象数组中特定键的值?