我有一个UserSchemamongoose架构:
var UserSchema = new Schema({
name: String,
username: String,
email: String,
role: {type: String, default: 'user'},
following: [{type: Schema.ObjectId, ref: 'User'}],
followers: [{type: Schema.ObjectId, ref: 'User'}],
hashedPassword: String,
provider: String,
salt: String,
facebook: {},
twitter: {},
github: {},
google: {}
});
Run Code Online (Sandbox Code Playgroud)
我创建了一个虚拟profile,它只返回公共配置文件的信息:
UserSchema
.virtual('profile')
.get(function() {
return {
'username': this.username,
'name': this.name,
'role': this.role
};
});
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在我提出find请求时只获取此信息.这是我的代码:
UserSchema.statics = {
list: function (options, callback) {
var criteria = options.criteria || {};
this.find(criteria)
.select(/* …Run Code Online (Sandbox Code Playgroud)