hello developer i have created a following schema
const playerSchema = new SimpleSchema({
name: { type: String },
userid: { type: String, regEx: SimpleSchema.RegEx.Id },
rating: { type: SimpleSchema.Integer }
});
const actionSchema = new SimpleSchema({
type: {
type: String,
allowedValues: ["move", "takeBack", "draw", "resigned", "aborted", "game"]
},
value: { type: String },
actionBy: { type: String }
});
const GameSchema = new SimpleSchema({
startTime: {
type: Date,
autoValue: function() {
return new Date();
}
},
requestBy: {type: String},
status: {type: String},
clocks: new SimpleSchema({
white: new SimpleSchema({
time: {type: SimpleSchema.Integer},
inc: {type: Number}
}),
black: new SimpleSchema({
time: {type: SimpleSchema.Integer},
inc: {type: Number}
})
}),
white: new SimpleSchema({
name: { type: String },
userid: { type: String, regEx: SimpleSchema.RegEx.Id },
rating: { type: SimpleSchema.Integer }
}),
black: new SimpleSchema({
name: { type: String },
userid: { type: String, regEx: SimpleSchema.RegEx.Id },
rating: { type: SimpleSchema.Integer }
}),
moves: [String],
actions: [actionSchema]
});
GameCollection.attachSchema(GameSchema);
After i successfully insert value this schema on game_create method
let game = {
date: new Date(),
// status: them.settings.autoaccept ? "playing" : "pending",
status: "pending",
requestBy: us._id,
clocks: {
white: { time: time * 60, inc: increment },
black: { time: time2 * 60, inc: increment2 }
},
white: {
name: white.username,
userid: white._id,
rating: white.rating
},
black: {
name: black.username,
userid: black._id,
rating: black.rating
},
moves:[],
actions: []
};
whne update game status pending to playing neither update nor throw error
GameCollection.update({ _id: game._id }, { $set: { status: "playing" }});