我正在尝试使用以下架构返回文档的所有'_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']
它只是指Schema中的数组,但我不是在搜索它们。有什么想法吗?提前谢谢。
答案 0 :(得分:2)
.find()
是Mongoose.Model
类的静态方法,但您不会调用现有的实例方法。这是一个正确的例子:
var Question = mongoose.model('Question', Question, 'Question');
Question.find().distinct( '_id' , function(err,questions){
// Some code
});