mongodb - How to change live date? -


i wonder, how change live data schema mongodb ?

for example if have "users" collection following document:

var user = {     _id:123312,     name:"name",     age:12,     address:{         country:"",         city:"",         location:""     } }; 

now, in new version of application, if add new property "user" entity, let weight, tall or adult ( based on users year ), how change current live data not have adult property. read mapreduce , group aggregation command but, seem comfortable , suitable analytic operation or other calculations, or wrong.

so best way change current running data schema in mongodb ?

it depends upon programming language. mongodb @ having dynamic schema. think pattern of thought @ moment sql related whereby believe rows, if not yet have value, must have new field.

the reality quite different. rows have nothing meaningful put them not require field , can, in application, check see if returned document has value, if not can assume, in fixed sql schema, value null.

so 1 aspect mongodb shines, fact don't have apply new field entire schema on demand, instead can lazy fill data entered user.

so code field application , let user work you.

the best way add field write loop, in maybe console close or on primary of replica (if have one, otherwise on server), so:

db.users.find().foreach(function(doc){     doc.weight = '44 stone';     db.users.save(doc); }); 

that best way asking.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -