0

I have the following model representing the existing json file.

Player = config.mongoose.model('Player', {

        birthday: {type: Date, required: true}, //
        nationality: {type: String, required: true}, //
        id: {type: Number, required: true}, //
        more: {
            injured: {type: Number, required: false},
            current_club: {type: Number, required: false},
        }
    }
);

module.exports = Player;

I want to add the amounth of goals scored to the player and save this. This has to be done underneath the current_club with required false. Also I want to update a nationality when a player decides to play for a country different from the one stored in existing json file.

What i basically want to know how to 'call' the model, walk trough it and save it.

kind regards

RichardB
  • 41
  • 4
  • Have you seen [this question](https://stackoverflow.com/questions/7617002/dealing-with-schema-changes-in-mongoose)? – m4gic Dec 03 '18 at 12:37
  • Thank you. Haven't seen this one no. It does suggest that you can add 'custum fields' to a model based on an existing json file. And by giving the newly added field a default value you make sure it finds a value from start? – RichardB Dec 03 '18 at 13:05
  • That was only the first answer. I would suggest to do what the third answer suggested too. (Please update your database to have the expected structure in every document, this will make your life easier later, you don't have to implement additional code to handle these missing/changed/introduced parts of your documents.) – m4gic Dec 03 '18 at 13:26
  • this program keeps 'walking through' this data, so if I get this right I should use the third answer at first startup so the 'current json file' will change to the desired format. and then log the changes (need to see progress per season e.g.) and then update it again. – RichardB Dec 03 '18 at 14:15

0 Answers0