javascript - 环回查询mongodb文档
问题描述
我试图查询子文档,但它会引发以下错误。
错误:无法调用 Project.find()。尚未设置查找方法。PersistedModel 未正确附加到数据源!
我只能在资源管理器中看到项目文档,我也想看到它的子文档用户。
项目.json
{
"name": "Project",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"description": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": "userId"
}
},
"acls": [],
"methods": {}
}
项目.js
'use strict';
module.exports = function(Project) {
Project.find().then((projects => console.log(projects))).catch((err) => console.log(err));
};
解决方案
尝试将您的代码更改为:
'use strict';
module.exports = function(Project) {
Project.find().exec().then((projects => console.log(projects))).catch((err) =>
console.log(err));
};
我将 .exec() 添加到查询中。
推荐阅读
- comments - 重置评论数
- javascript - 使用 youtube 等灰色条预加载内容
- html - 如何将按钮连接到 ruby on rails 上的数据库?
- material-design - Flutter 中的 Material Design 维度
- spss-modeler - SPSS Cloud 无法打开/创建临时文件
- c++ - 将 int32 重新解释为浮动
- python - sampled_softmax_loss 如何从 softmax 嵌入矩阵中知道要使用哪个嵌入?
- python - 合并数据框
- typescript - 如何在离子列表中添加广告横幅
- circleci - CircleCi 2.0 在子目录中使用项目