从mongodb集合获取所有文档时出错
Getting error while fetching all documents from a mongodb collection
I am getting this error
> [ERROR] TypeError: undefined is not a function
while fetching all documents from a collection.
My Code is below:
Calender JS
Model:
var taskCalenderSchema = new mongoose.Schema({
user_id:{type:String, required: false, unique:false},
task_data:{},
from: {type: Date, required: false, unique:false},
to: {type: Date, required: false, unique:false}
});
module.exports = mongoose.model('task_calender', taskCalenderSchema);
exports.schema = taskCalenderSchema;
Task JS
exports.getAllTasks = function(request, response){
Calender.find({}, function(error, listOfTasks){
if(error){
response.json({status: false, msg : 'Some thing wrong while getting tasks list'});
}else{
response.json({status: true, data: listOfTasks});
}
});
};
我已经在上面写了代码。在模型中,我创建了模式。保存的文档,但同时检索我得到了这个错误我得到这个错误:
从收集
实际上,我没有准确地指向引用。由于在Calendar JS中,我使用导出
module.exports=猫鼬.model('task_calenders',taskCalenderSchema(;
在任务Js中,我引用了它,以这种方式
var日历=需要('../../../ZemModels/Calender'(.model;
这是错误的。正确的语法是
var日历=需要('../../../ZemModels/Calender'(;
简而言之,当我们使用module.exports导出模式时,就不需要在引用的文件中使用模型。如果我们使用模型导出模式,则使用模型。
相关文章:
- 使用promise和mongoose对文档进行排序
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- Ajax请求文档就绪会导致jquery加载缓慢
- MongoDB (php) - 以数组而不是多个属性的形式返回文档属性
- 谷歌文档表面引擎
- 来自文档或下一个静态父级的事件委派
- 如何将childNodes用于XML文档
- 文档就绪提供了错误的选择器高度
- 将当前用户的 ID 推送到 meteorjs 中集合/文档的内部数组
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- XPath 出错.节点不能在创建节点的文档以外的文档中使用
- 尝试从 dom 文档中删除 dom 节点时出错
- 导入BSON文档MongoDB时出错
- 文档元素Firefox之后的垃圾使用JQuery Get加载内容时出错
- 使用mongoDB和node.js更新文档时出错
- 根据文档,在承诺中抛出错误会拒绝它,但它不会
- 从mongodb集合获取所有文档时出错
- 尝试获取文档时出错.getElementsByName(name)
- 使用 JQuery 在文档就绪上加载 AJAX 时出错
- 执行'write'& # 39;文档# 39;加载角度谷歌地图时出错