我有一个代表玩家的猫鼬模型,希望能够获取玩家,并且在选择玩家时,想要isReady像 getter 一样调用。
该模型如下所示:
const PlayerSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: "User" },
famousPerson: { type: String }
})
PlayerSchema.methods.isReady = function (cb) {
return Boolean(this.famousPerson)
}
我希望能够这样称呼它:
const player = await PlayerModel
.findOne({_id: playerId})
.select(["_id", "username", "isReady"])
我可以将类上的方法设置为吸气剂吗?
呼如林
缥缈止盈
相关分类