[英]Gendered my _id with firstname and lastname
嘿,我将在mongodb中生成带有名字和姓氏的_id,但是我对此有疑问,我将生成这样的ID:'_id':'midoxnavas'将Midox名字和navas姓氏
var bcrypt = require('bcrypt-nodejs'),
_ = require('underscore'),
mongoosePaginate = require('mongoose-paginate');
module.exports = function (mongoose) {
var Schema = mongoose.Schema;
// noinspection JSAnnotator
var UserSchema = new Schema({
_id='firstName'+'lastName',
firstName: String,
lastName: String,
userName: {type: String, unique: true},
email: {type: String, unique: true},
password: String,
salt: String,
role : {type: String, enum : ['User','Manager','Admin']},
});
// generating a hash
UserSchema.methods.generateHash = function (password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
// checking if password is valid
UserSchema.methods.validPassword = function (password) {
return bcrypt.compareSync(password, this.password);
};
UserSchema.plugin(mongoosePaginate);
module.exports = mongoose.model('User', UserSchema);
}
错误是
_id='firstName'+'lastName',
^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
有什么解决办法吗?
_id
自动生成。
我认为您需要创建virtual
字段文档
PersonSchema
.virtual('name.full')
.get(function () {
return this.name.first + ' ' + this.name.last;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.