以下代码来自mongoose文档:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Schema = mongoose.Schema;
// define a schema
var animalSchema = new Schema({name:String, type:String});
// assign a function to the "methods" object of our animalSchema
animalSchema.methods.findSimilarTypes = function(cb){
return this.model('Animal').find({ type: this.type }, cb);
}
var Animal = mongoose.model('Animal', animalSchema);
var dog = new Animal({ type: 'dog' });
dog.findSimilarTypes(function(err, dogs) {
console.log(dogs); // woof
});
首先'this'指的是什么对象?它是'文件'对象狗吗?在API中找不到'文档'上的任何“模型”方法?