2016-10-20 9 views
0

Ich versuche einen Datensatz vom Client zu aktualisieren, erhalte aber weiterhin einen Fehler. Versucht, alles in ein data = {} Objekt zu setzen und es an meine Meteor.call Methode zu übergeben, aber konnte es immer noch nicht zum Laufen bringen.Ungültiger Modifikator, Modifikator muss Objekt sein Fehler

Browser: errorClass {error: 500, reason: "Internal server error", details: undefined, message: "Internal server error [500]", errorType: "Meteor.Error"}

Server: Exception while invoking method 'updateComment' Error: Invalid modifier. Modifier must be an object.

Ich weiß, es mit dem zu tun hat, wie ich meine updateComment Methode nenne. Würde es mir etwas ausmachen, mich in die richtige Richtung zu lenken?

Vielen Dank im Voraus.

Aktueller Code:

Kommentare/methods.js

updateComment: function (commentId, commentContent, userId, fritkotId) { 
    // check(commentId, String); 
    // check(commentContent, String); 
    // check(userId, String); 
    // check(firtkotId, String); 
    Comments.update({ 
      _id: commentId, 
      body: commentContent, 
      author: userId, 
      fritkotId: fritkotId, 
      modifiedAt: new Date() 
     }); 
}.... 

editComment.js

import './editComment.tpl.jade' 

// Events 
Template.editComment.events({ 
'click .form-save': (e) => { 

    e.preventDefault(); 

    let data = {}; 

    let commentContent = $('.update-comment').val(); 

    let fritkotId = Fritkots.findOne({})._id; 
    let commentId = Comments.findOne({})._id; 
    let userId = Meteor.userId(); 

    // data.commentId = commentId; 
    // data.commentContent = commentContent; 
    // data.userId = userId; 
    // data.fritkotId = fritkotId; 

    console.log(` This is the commentId: ${commentId}, userId: ${userId}, fritkotId: ${fritkotId}`); 

    Meteor.call('updateComment', commentId, commentContent, userId, fritkotId, function(error) { 
     if (!error) { 
      console.log('comment updated'); 
     } else { 
      console.log(error); 
      console.log('unable to update comment'); 
     } 
    }) 

    console.log(`The comment was updated to this ${commentContent}`); 

    console.log('I was clicked for save'); 

    // Session.set('editCommentId', false); 
    Session.set('editCommentId', null); 
}, 
.... 

Sammlungen/comments.js

Comments = new Mongo.Collection('comments') 

// Permissions 
Comments.allow({ 
    insert:() => false, 
    // update: (userId, doc) => { return !! userId; }, 
    update:() => false, 
    remove:() => false 
}); 

Comments.deny({ 
    insert:() => true, 
    update:() => true, 
    // update: (userId, doc) => { return !! userId; }, 
    remove:() => true 
}); 

Antwort

1

Sie müssen einen Weg finden, um den Kommentar zu identifizieren, und dann die Teile übergeben, die Sie ändern möchten. Es gibt definitiv ein Problem bei der Verwendung von .update() (siehe Dokumentation).

Ich glaube, Sie so etwas wie dies will:

Comments.update(id, {$set: {key: value}}) 

oder diesen

Comments.update(id, {$set: {key: value}}) 
+0

Dank, dass das Problem gelöst. – intercoder

Verwandte Themen