修饰符无效,修饰符必须是对象错误

时间:2016-10-20 07:17:42

标签: javascript mongodb meteor meteor-blaze

我正在尝试从客户端更新记录,但一直收到错误。尝试将所有内容放入data = {}对象并将其传递给我的Meteor.call方法,但仍然无法使其工作。

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

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

我知道这与我如何调用我的updateComment方法有关。有人会介意我指出正确的方向。

提前致谢。

当前代码:

评论/ 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);
},
....

collections / 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
});

1 个答案:

答案 0 :(得分:1)

您需要找到识别评论的方法,然后传入您想要更改的部分。使用.update()(检查文档)肯定存在问题。

我相信你想要这样的东西:

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

或者

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