在Meteor.js中使用mongo update命令的CollectionFS

时间:2014-09-04 12:25:49

标签: mongodb meteor

在我的meteor.js应用程序中,我正在尝试使用CollectionFS更新组的图片。

var groupimage = Images.insert(file);
Groups.update(groupId, {$set: { photo: groupimage }}, function(error) {
            if (error) {
                // display the error to the user
                throwError(error.reason);
            } else {
                console.log('mongo document new');
                console.log(Groups.findOne({_id:groupId}));

            }
        });

这不起作用,它会出现此错误:

Exception in delivering result of invoking '/groups/update': ReferenceError: throwError is not defined
at http://localhost:3000/client/views/groups/editgroup/editgroupgeneral/editgr…dropzoneeditgroupgeneral.js?a1c6bb6d6c464c579ca4a82ca9f92775df17f5c5:39:21
at wrappedCallback (http://localhost:3000/packages/mongo-livedata.js?9213dc77ff40001575341a02827a8f1ed3200d98:531:9)
at null._callback (http://localhost:3000/packages/meteor.js?47d1d2b71177463dc159606cf930e44b9e3337f6:831:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3802:12)
at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3822:10)
at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:4831:9)
at onMessage (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3667:12)
at http://localhost:3000/packages/livedata.js?     32d6f3870045baedecfa7c0d90861ead2810da37:2710:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11) 

但是当我插入而不是更新时,一切都运行得很好。这很有效。

 var groupimage = Images.insert(file);
        Groups.insert({
            name: 'My Group',
            photo: groupimage
        });

我的更新有什么问题?谢谢。

修改

Exception in delivering result of invoking '/groups/update': Error
at http://localhost:3000/client/views/groups/editgroup/editgroupgeneral/editgr…dropzoneeditgroupgeneral.js?c24e8998d12b9aaa84912c2e87ec327e47277070:39:27
at wrappedCallback (http://localhost:3000/packages/mongo-livedata.js?9213dc77ff40001575341a02827a8f1ed3200d98:531:9)
at null._callback (http://localhost:3000/packages/meteor.js?47d1d2b71177463dc159606cf930e44b9e3337f6:831:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3802:12)
at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3822:10)
at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:4831:9)
at onMessage (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3667:12)
at http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:2710:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11) 

修改2

errorClassdetails: undefinederror: 409errorType: "Meteor.Error"message: "MongoError: not okForStorage [409]"reason: "MongoError: not okForStorage"stack: (...)get stack: function () { [native code] }arguments: nullcaller: nulllength: 0name: ""prototype: Object__proto__: function Empty() {}<function scope>set stack: function () { [native code] }__proto__: Middle

1 个答案:

答案 0 :(得分:0)

您应该使用Meteor的error method代替:

 throw new Meteor.Error(500, error.reason);