我正在开发一个Web应用程序。后端部分是使用Mongoose用NodeJS编写的。
我有一个简单的用户架构:
const UsersSchema = new Schema({
login: {
type: String,
required: true,
lowercase: true,
trim: true,
unique: true
},
password: {
type: String,
required: true,
trim: true
},
email: {
type: String,
required: true,
trim: true
},
firstName: {
type: String,
required: true,
trim: true
},
lastName: {
type: String,
required: true,
trim: true
}
});
Run Code Online (Sandbox Code Playgroud)
我需要返回以添加该fullName
属性,而无需将其实际添加到数据库中。我当然可以那样串联this.firstName + " " + this.lastName
。
但是我想知道是否有更好的方法来获得期望的行为。
我还使用mongoose-pagination-2
库来支持项目的分页:
const users = await Users.paginate({}, queryParams);
Run Code Online (Sandbox Code Playgroud)
请给一些建议。谢谢。