mercredi 15 avril 2015

Is there a way to add/subtract all fields inside a JSON with another object with the same fields?

I have a Mongoose.js schema (but you probably don't need to know that), which looks like this:



{
"City": String,
"Year": String,
"Population": Number,
"Blah": Number,
"Nested": {
"Something": Number,
"More stuff": Number
}
}


Is there a convenient/best method to take another object with the same fields and add its number fields with this one's or do I need to write a function to actually go in and do that?


I'm dealing with a very large schema here. If I write a function to do this, I'll have to manually maintain it; meaning if I change the schema, I'll have to manually change the member function I define to add stuff.


Aucun commentaire:

Enregistrer un commentaire