I'm trying to add an object to an object array that is a key in a collection entry with the following code, but I'm getting a weird response "insert failed: Error: Title is required". I'm using simple schema/autoform on meteor.
Has anyone encountered this before (and have a solution)?
Template.dashboard.events({
'click .requestinvite'(e,t) {
Posts.insert({ _id : $(e.currentTarget).attr('_id')},
{$push: { invitesRequested : {username : Meteor.userId()} }}
);
}
});
Here is the relevant Simple Schema in coffeescript
Schemas.Posts = new SimpleSchema
title:
type:String
max: 60
optional: true
content:
type: String
optional: false
autoform:
rows: 5
createdAt:
type: Date
autoValue: ->
if this.isInsert
new Date()
updatedAt:
type:Date
optional:true
autoValue: ->
if this.isUpdate
new Date()
invitesRequested:
type: [Object]
optional: true
defaultValue: []
owner:
type: String
regEx: SimpleSchema.RegEx.Id
autoValue: ->
if this.isInsert
Meteor.userId()
autoform:
options: ->
_.map Meteor.users.find().fetch(), (user)->
label: user.emails[0].address
value: user._id
The answer was using Posts.update instead. But Ankur Soni's post lead me in the right direction to troubleshoot this down.