嘿我将使用mongodb中的firstname和lastname生成我的_id,但是我对此有问题,我将生成这样的id:'_ id':'midoxnavas'将midox firstname和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
你有解决方案吗?
答案 0 :(得分:0)
_id
- 自动生成。
我认为您需要创建virtual
字段docs
PersonSchema
.virtual('name.full')
.get(function () {
return this.name.first + ' ' + this.name.last;
});