2014-09-04 52 views
0

在我的meteor.js应用程序中,我尝试使用CollectionFS更新组的图片。CollectionFS与Meteor.js中的mongo更新命令

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 
+0

如何以及在哪里是函数'throwError'实施? – Tobold 2014-09-04 13:29:55

+0

我没有自己实现它 – user2858924 2014-09-04 13:42:25

回答

0

你也许应该使用流星的error method代替:

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

我做了,检查编辑 – user2858924 2014-09-04 14:44:02

+0

哇,明确......你可能'console.log(错误)'而不是,并检查输出? – SylvainB 2014-09-04 14:54:17

+0

我做到了。检查编辑2.它给mongodb错误,但奇怪的是,它没有给出任何插入错误。所以也许,它只有更新命令的问题。 – user2858924 2014-09-05 08:01:12