javascript - Setting default on Mongoose subschema automatically -
i looking way have mongoose automatically fill in field generated value. thought following work it's no go. possible autofill sub schema field on save? (not looking middleware code - automatic)
// function gen integer function randomvalue () { var s = parseint(crypto.randombytes(4).tostring('hex'), 16); return s; } // subschema var variation = new schema({ // set default gen integer code: { type: number, default: randomvalue } },{ _id : false }); // main schema var product = new schema({ variations: { type: [variation] } });
you need invoke randomvalue in order return value of s
Comments
Post a Comment