These are chat archives for Automattic/mongoose

26th
Jul 2017
Alex
@alexc101
Jul 26 2017 13:11
Hi, I'm using Koa with Mongoose/Bluebird and I'm trying to set up a check password sequence. This works, but I'm not sure if it's good practice?
UserSchema.methods.validPassword = function (password) {
    if(bcrypt.compareSync(password, this.password)){
        return true
    }
    else {
        throw new Error('password\'s do not match')
    }
};

const req = ctx.request.body;
const userId = ctx.request.body.userId;

await User.findById(userId)
    .then(user => user.validPassword(req['currentPassword']) ? user : null)
    .then(user => {
        console.log(user)
    })
    .catch((err) => {
        ctx.body = {
            err: err.message
        }
    })
Tobias Lundgren
@lundgren2
Jul 26 2017 20:48

I have an JSON object that I have to store in a database under an customer…

What is the best way to store this? How should the scheme looks like? Please help <3

{
  "Brands": {
    "Brand1": {
      "stands": {
        ...different amount of stands
      }
    }
    "Brand2": {
      "stands": {
        ...different amount of stands
      }
    }
    ... different amount of brands
  } 
}