“this”在下面的代码中代表“this.model('Animal')”和“this.type”是什么?

嘿,我是新的mongoose和节点。我有点混淆在下面的代码:

var animalSchema = new Schema({ name: String, type: String }); 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); }); 

this实例代表在this.model('Animal')this.type在下面的代码?

在像findSimilarTypes this的实例方法中, this是数据库中文档的模型实例。

所以this.model('Animal')正在查找Animal模型,而this.type是调用findSimilarTypes时使用的模型实例的type属性。