对象在搜索不同的“_id”时没有找到方法

object has no find method when searching for distinct '_id'

我正在尝试 return 使用以下架构的文档的所有“_id”值:

var QuestionSchema = new Schema ({
    author: { type: String },
    title: { type: String },
    subject: { type: String },
    topic: { type: String },
    question: { type: String }, 
    correct_ans: { type: Number },
    explanation: { type: String },
    answers: [ String ],
    answer_stats: [ Number ], 
    tags: [ String ],
    publish: { type: Boolean }
});

但是,当我运行下面的代码时:

var Question = mongoose.model('Question', Question, 'Question');
var question = new Question();
question.find().distinct( '_id' , function(err,questions){
    // Some code
});

我收到以下错误:

[TypeError: Object { _id: 54cf53aec22cbf242b9cde43,
  tags: [],
  answer_stats: [],
  answers: [] } has no method 'find']

它只是指模式中的数组,但我没有搜索它们。有什么想法吗?提前致谢。

.find()Mongoose.Model class 的静态方法,但您调用的是不存在的实例方法。这是一个正确的例子:

var Question = mongoose.model('Question', Question, 'Question');
Question.find().distinct( '_id' , function(err,questions){
  // Some code
});

请参阅 Mongoose Queries Docs and Mongoose API Docs 了解更多信息。