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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -