【问题标题】:mongoose find is not a function猫鼬 find 不是一个功能
【发布时间】:2018-02-16 14:07:09
【问题描述】:

我有一个报告模型:

const mongoose = require('mongoose');


var Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;

const reportSchema = new mongoose.Schema({
    score: Number, 
    notes: String, 
    user: ObjectId, 
    date: Date
}, {timestamps: true})

const Report = mongoose.model('Report', reportSchema);

module.exports = Report

但是当我发现它说函数不存在:

report.find({}, function(err, docs){
    console.log(docs)
  })

【问题讨论】:

  • 你的意思是Report 是吗?你怎么require举报模特?
  • 您的文件中是否需要猫鼬?
  • 实际上,既然您提到了它,我正在使用以下报告,这可能是我的问题: var report = new Report({ score: req.body.score, notes: req.body.notes , 用户: req.user.id, 日期: mydate });
  • 看起来是区分大小写的问题。使用报告而不是报告

标签: node.js mongoose


【解决方案1】:

真正的问题是我认为模型已添加,但事实并非如此。

【讨论】:

    猜你喜欢
    • 2018-02-12
    • 2019-01-18
    • 2020-12-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2020-01-17
    相关资源
    最近更新 更多