Hey i will generated my _id with firstname and lastname in mongodb but i have problem with this,i will generated id like this : '_id':'midoxnavas' will midox firstname and navas last name
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);
}
the erreur is
_id='firstName'+'lastName',
^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
Have you any solution ?
_id
- generate automaticly.
I think you need create virtual
field docs
PersonSchema
.virtual('name.full')
.get(function () {
return this.name.first + ' ' + this.name.last;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.