我正在通過Discover Meteor書籍工作,並試圖使用Method.call編輯帖子(第8章),而不是使用更新/刪除客戶端數據操作。Meteor方法成功更新了數據庫,但返回了500錯誤到Meteor.call
該呼叫成功呼叫postModify
方法,該方法更新Posts
集合。問題在於Method正在返回500內部服務器錯誤,而不是返回Meteor.call的結果。
我認爲Posts.update
或postModify
方法中的return語句會觸發錯誤。
這是電話。
Template.postEdit.events({
'submit form': function(e) {
e.preventDefault();
var postProperties = {
url: $(e.target).find('[name=url]').val(),
title: $(e.target).find('[name=title]').val(),
_id: this._id
};
Meteor.call('postModify', postProperties, function (error, result) {
if (error)
return alert(error.reason);
Router.go('postPage', {_id: result._id});
}); } });
這是postModify
流星法。
Meteor.methods({
postModify: function(updatedPost) {
var currentPostId = updatedPost._id;
var newTitle = updatedPost.title;
var newUrl = updatedPost.url;
var modifiedPost = Posts.update({_id: currentPostId}, {$set: {
title: newTitle,
url: newUrl
}});
console.log("the post has been updated");
return {
_id: modifiedPost
}; } });
這是路線:
Router.route('/posts/:_id', {
name: 'postPage',
data: function() {
return Posts.findOne(this.params._id); }
});
這是WebSocket的消息:
["{\"msg\":\"method\",\"method\":\"postModify\",\"params\":[{\"url\":\" testing.com\",\"title\":\"Daniel is1\",\"_id\":\"apT8KEC7z8ci3TFD4\"}],\"id\":\"2\"}"]
a["{\"msg\":\"result\",\"id\":\"2\",\"error\":{\"error\":500,\"reason\":\"Internal server error\",\"message\":\"Internal server error [500]\",\"errorType\":\"Meteor.Error\"}}"]
下一行顯示的是收集已成功更新:
這是l從外殼og:
I20151006-10:27:14.098(-7)? the post has been updated
I20151006-10:27:14.099(-7)? { isSimulation: false,
I20151006-10:27:14.099(-7)? _unblock: [Function],
I20151006-10:27:14.099(-7)? _calledUnblock: false,
I20151006-10:27:14.099(-7)? userId: 'cLzs8ixMfgXeHLXLc',
I20151006-10:27:14.099(-7)? _setUserId: [Function],
I20151006-10:27:14.100(-7)? connection:
I20151006-10:27:14.100(-7)? { id: 'bXSjdEXHC3utPYMDn',
I20151006-10:27:14.100(-7)? close: [Function],
I20151006-10:27:14.100(-7)? onClose: [Function],
I20151006-10:27:14.100(-7)? clientAddress: '127.0.0.1',
I20151006-10:27:14.100(-7)? httpHeaders:
I20151006-10:27:14.100(-7)? { 'x-forwarded-for': '127.0.0.1',
I20151006-10:27:14.101(-7)? host: 'localhost:3000',
I20151006-10:27:14.101(-7)? 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
I20151006-10:27:14.101(-7)? 'accept-language': 'en-US,en;q=0.8' } },
I20151006-10:27:14.101(-7)? randomSeed: null,
I20151006-10:27:14.101(-7)? randomStream: null } 'apT8KEC7z8ci3TFD4' 'Daniel is1' ' testing.com' 1
I20151006-10:27:14.109(-7)? Exception while invoking method 'postModify' Error: Did not check() all arguments during call to 'postModify'
I20151006-10:27:14.109(-7)? at [object Object]._.extend.throwUnlessAllArgumentsHaveBeenChecked (packages/check/packages/check.js:365:1)
I20151006-10:27:14.110(-7)? at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/packages/check.js:120:1)
I20151006-10:27:14.110(-7)? at maybeAuditArgumentChecks (livedata_server.js:1689:18)
I20151006-10:27:14.110(-7)? at livedata_server.js:708:19
I20151006-10:27:14.110(-7)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151006-10:27:14.110(-7)? at livedata_server.js:706:40
I20151006-10:27:14.111(-7)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151006-10:27:14.111(-7)? at livedata_server.js:704:46
I20151006-10:27:14.111(-7)? at tryCallTwo (/Users/danielvitiello/.meteor/packages/promise/.0.5.0.97m7hz++os+web.browser+web.cordova/npm/node_modules/meteor-promise/node_modules/promise/lib/core.js:45:5)
I20151006-10:27:14.111(-7)? at doResolve (/Users/danielvitiello/.meteor/packages/promise/.0.5.0.97m7hz++os+web.browser+web.cordova/npm/node_modules/meteor-promise/node_modules/promise/lib/core.js:171:13)
謝謝你看看這個問題。
應該在您的shell中打印一個錯誤,詳細描述服務器上發生了什麼 - 這是什麼意思? –
'collection.update(selector,modifier,[options],[callback])'返回受影響文檔的數量。因此,我認爲你的'modifiedPost'變量不包含更新的文檔。 –
@DavidWeldon用日誌更新了OP –