I have a user collection where the json may look like so.
{
_id: "someuserid",
services: {},
games: [{
warcraft: {
'days': [0,1,2,3,4,5,6],
'times': [0,1,2]
}
}],
roles: {
'warcraft': ['pvp', 'raid']
}
I had a little trickery because I had to create autoValues
on my schema such that only a subset of days could be selected. That is:
"games.$.times": {
type: [Number],
autoform: {
options: function () {
// there are set raid times you can participate in
return [
{ label: "Morning", value: '0'},
{ label: "Afternoon": value '1' },
{ label: "Evening", value: '2' },
{ label: "Morning and Afternoon", value: '0;1' },
{ label: "Morning, Afternoon, and Evening", value: '0;1;2' },
]
}
},
autoValue: function () {
if (_.isArray(this.value)) {
return this.value.map(Number);
} else if (_.isNumber(this.value)) {
return [this.value];
// if it's from the form, split it on the delimiter
} else if (_.isString(this.value)) {
return this.value.split(';').map(Number);
}
}
}
So now if I go to a user’s profile and log the user, I get the expected value in the javascript console.
> Meteor.users.findOne().games.map(function (game) {
return game.times;
});
[0, 1, 2];
However, when I call a meteor method and pass the user, it mutates the value.
var user = Meteor.users.findOne();
Meteor.call('Player.invite', user);
// on server
'Player.invite': function (playerDoc) {
console.log(playerDoc.games.map(function (game) { return game.times }))
}
this gives me [';', 0, 1, 2]
What’s going on? Why is the server having different values than the client?