Brandon
Brandon

Reputation: 259

When attempting to remove a document in Meteor: "Remove failed: Internal server error"

I am attempting to remove a document by the ObjectId.

Template.conferenceItem.events({
    'click #delete' : function () {
        Conferences.remove(this._id);
    }
});

In my console I get "remove failed: Internal server error". I get the same error if I run this in the console: Conferences.remove('tfD9KQsFp8LoftHgS'), where tfD9KQsFp8LoftHgS is an existing ObjectId.

Edit:

I have the following code in my collections folder in conferences.js:

Conferences = new Meteor.Collection('conferences');

Conferences.allow({
  remove: function(userID, doc){
    // only allow remove if you are logged in
    return !! userId;
  }
});

Upvotes: 1

Views: 658

Answers (2)

Wes
Wes

Reputation: 71

I believe you have a typo in the function associated with remove. The meteor doc example

remove: function (userId, doc) {
    // can only remove your own documents
    return doc.owner === userId; 
}

so change userID to userId

Upvotes: 0

JohnAllen
JohnAllen

Reputation: 7521

This is probably a Meteor allow error.

Collection.allow: Allow users to write directly to this collection from client code, subject to limitations you define.

You must authorize your untrusted client code to allow removes on the server somewhere in your code?

You probably want to do something like this, in your server code:

Conferences.allow({

  remove: function (userId, doc) {
  // check for proper permissions using passed arguments if any here
  return true;
}

});

Upvotes: 1

Related Questions