lykmapipo / seed-mongoose

DRY data seeding for mongoose
14 stars 2 forks source link

Add ability to exclude fields from criteria #5

Open tankist opened 7 years ago

tankist commented 7 years ago

Currently there is no possibility to exclude some fields from the find criteria and so sometimes not all existing records deleted.

I propose to modify seed process to give user ability to define excluded fields or to define criteria itself

akaNightmare commented 7 years ago

example for that: UserSeed.js

module.exports = [
  {
    "email": "test@test.com",
    "password": "123",
  },
];

models/User.js -> mongoose model

userSchema.pre('update', beforeSave);
userSchema.pre('save', beforeSave);

function beforeSave(next) {
    if (this.isModified('password')) {
        this.password = bcrypt.hashSync(this.password, SALT_ROUNDS);
    }
    return next();
}