Friday, March 27, 2015

Mongoose value defaulting


Pretty neat way of defaulting object values in mongoose. Say you want to have a default proximity uuid assigned to one of your documents. Simply enclose this in a type and default definition like the one below. Added bonus of being quite readable as well.

beaconProximityUUID: {type: String, default: BEACON_PROXIMITY_UUID}

1 comment:

Parker Edward said...

I was trying with the wrong command optional. The write essay for me not sure from where I got that. Anyways this is working thanks for the great help.