I have an image gallery with a forward and backward-button. on a click on either of the buttons i want to upsert an entry in the local database with the times the image has been viewed (so i can later see which image has been viewed the most).
This works perfectly without the Schema:
'click .btn-forward, click .btn-backward' (event, template) {
Local.Viewed.upsert({
imageId: this._id
}, {
$setOnInsert: {
imageId: this._id,
imageName: this.name
},
$inc: {
timesViewed: 1
}
});
}
});
The Schema:
Local.Viewed.Schema = new SimpleSchema({
imageId: {
type: String
},
imageName: {
type: String
},
timesViewed: {
type: Number,
defaultValue: 0
},
createdAt: {
type: Date,
autoValue: function() {
return new Date();
}
}
});
Problem:
When i use this Schema i get an error:
update failed: Error: Times viewed is required at getErrorObject
The Schema seems to be demanding that 'timesViewed' is set. I tried using 'defaultValue: 0' in the Schema but that doesn't insert a default Value of 0.
Question: How can i make the Schema compatible with this query?
Thanks for your help!
Muff