I’m following the example from the Discover Meteor book for my own application and I’m getting an error when inserting the record:
Exception in delivering result of invoking ‘artistInsert’: assert
I’ve verified that the data is being inserted into the collection, but I still get this error and doesn’t return to the page I’ve set in the Router.go method.
The js calling code:
Template.artistSubmit.events({
‘submit form’: function(e) {
e.preventDefault();
var artistInfo = { name: $(e.target).find('[name=artistName]').val(), genre: $(e.target).find('[name=artistGenre]').val() };
Meteor.call('artistInsert', artistInfo, function(error, result) { // display the error to the user and abort if (error) return alert(error.reason);
// show this result but route anyway if (result.artistExists) alert('This artist has already been added.');
Router.go('artistList');
});
}
});
My artists.js method within /lib/collections/artist.js:
Artists = new Mongo.Collection(‘artists’);
Meteor.methods({
artistInsert: function(artistAttributes) {
check(this.userId, String);
check(artistAttributes, {
name: String,
genre: String
});
var artistWithSameName = Artists.findOne({name: artistAttributes.name}); if (artistWithSameName) { return { artistExists: true, _id: artistWithSameName._id } }
var user = Meteor.user(); var theArtist = _.extend(artistAttributes, { userId: user._id, owner: user.username, added: new Date() });
var artistId = Artists.insert(theArtist); return { _id: artistId };
}
});