mongoose - MongoDB empty string value vs null value -


in mongodb production, if value of key empty or not provided (optional), should use empty string value or should use null value.

1) there pros vs cons between using empty string vs null?

2) there pros vs cons if set value undefined remove properties existing doc vs letting properties value either empty string or null?

thanks

i think best way undefined suggest not including key altogether. mongo doesn't work sql, have have @ least null in every column. if don't have value, don't include key. if make query documents, key doesn't exists work correctly, otherwise not. if don't use key save little bit of disk space. correct way in mongo.

function deleteempty (v) {    if(v==null){      return undefined;    }    return v; }  var userschema = new schema({ email: { type: string, set: deleteempty }  }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -