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

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -