Meteor JS - 来自子 ID 的异常(不存在的 ID)
Meteor JS - Exception from sub id (id that does not exist)
I20150615-07:11:17.859(9)? Exception from sub draftsList id
GghnkQkdjNSTyHuQs Error: Match error: Expected object, got undefined
I20150615-07:11:17.859(9)? at checkSubtree
(packages/check/match.js:275:1) I20150615-07:11:17.859(9)? at
check (packages/check/match.js:32:1) I20150615-07:11:17.859(9)? at
[object Object].Meteor.publish.Meteor.users.find.userId [as _handler]
(app/server/publications.js:44:3) I20150615-07:11:17.859(9)? at
maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
I20150615-07:11:17.859(9)? at [object Object]._.extend._runHandler
(packages/ddp/livedata_server.js:950:1) I20150615-07:11:17.859(9)?
at [object Object]._.extend._startSubscription
(packages/ddp/livedata_server.js:769:1) I20150615-07:11:17.859(9)?
at [object Object]._.extend.protocol_handlers.sub
(packages/ddp/livedata_server.js:582:1) I20150615-07:11:17.859(9)?
at packages/ddp/livedata_server.js:546:1 I20150615-07:11:17.860(9)?
Sanitized and reported to the client as: Match failed [400]
我正在做一个流星项目,我的终端出现了这个奇怪的错误。
问题是当它说 Exception from sub draftsList id GghnkQkdjNSTyHuQs Error: Match error: Expected object, got undefined
时,id 总是在页面刷新时改变,并且不在我的数据库中(无处可见)。
事实是,一切正常发现..
这是我的publication-subscription
发表
Meteor.publish('draftsList', function (options) {
check(this.userId, String);
check(options, {
limit: Number
});
var drafts = Drafts.find({'user._id': this.userId}, options);
return drafts;
});
订阅
Router.route('/posts/:_id', {
name: 'postPage',
// limit: function () {
// return
// }
subscriptions: function () {
return [
Meteor.subscribe('singlePost', this.params._id),
Meteor.subscribe('userStatus'),
Meteor.subscribe('draftsList'),
Meteor.subscribe('draftsList', {
limit: Number(Session.get('draftsLimit'))
}),
Meteor.subscribe('comments', {
postId: this.params._id
}, {
limit: Number(Session.get('commentLimit'))
}),
Meteor.subscribe('answers', {
postId: this.params._id
}, {
limit: Number(Session.get('answerLimit'))
})
];
},
data: function() {
return Posts.findOne({_id:this.params._id});
},
});
尝试在您的出版物中删除针对 this.userId
的 check
,您无需检查此 属性 有效性,因为 Meteor 已经为您完成了。
Meteor.publish('draftsList', function (options) {
check(options, {
limit: Number
});
var drafts = Drafts.find(this.userId, options);
return drafts;
});
您在您的路线中订阅了两次 draftsList
。第一个订阅没有任何参数,这将使 options
成为 undefined
而不是对象。只需删除第一个订阅,问题就会消失。
另请注意,在这种情况下,将 check
用于 this.userId
可能有效,但如果您在路线中使用 waitOn
,则可能会导致问题。当 this.userId
在需要经过身份验证的客户端的发布者中 undefined
时,普遍接受的模式是 return []
或 this.ready()
。
I20150615-07:11:17.859(9)? Exception from sub draftsList id GghnkQkdjNSTyHuQs Error: Match error: Expected object, got undefined I20150615-07:11:17.859(9)? at checkSubtree (packages/check/match.js:275:1) I20150615-07:11:17.859(9)? at check (packages/check/match.js:32:1) I20150615-07:11:17.859(9)? at [object Object].Meteor.publish.Meteor.users.find.userId [as _handler] (app/server/publications.js:44:3) I20150615-07:11:17.859(9)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1) I20150615-07:11:17.859(9)? at [object Object]._.extend._runHandler (packages/ddp/livedata_server.js:950:1) I20150615-07:11:17.859(9)?
at [object Object]._.extend._startSubscription (packages/ddp/livedata_server.js:769:1) I20150615-07:11:17.859(9)?
at [object Object]._.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582:1) I20150615-07:11:17.859(9)?
at packages/ddp/livedata_server.js:546:1 I20150615-07:11:17.860(9)? Sanitized and reported to the client as: Match failed [400]
我正在做一个流星项目,我的终端出现了这个奇怪的错误。
问题是当它说 Exception from sub draftsList id GghnkQkdjNSTyHuQs Error: Match error: Expected object, got undefined
时,id 总是在页面刷新时改变,并且不在我的数据库中(无处可见)。
事实是,一切正常发现..
这是我的publication-subscription
发表
Meteor.publish('draftsList', function (options) {
check(this.userId, String);
check(options, {
limit: Number
});
var drafts = Drafts.find({'user._id': this.userId}, options);
return drafts;
});
订阅
Router.route('/posts/:_id', {
name: 'postPage',
// limit: function () {
// return
// }
subscriptions: function () {
return [
Meteor.subscribe('singlePost', this.params._id),
Meteor.subscribe('userStatus'),
Meteor.subscribe('draftsList'),
Meteor.subscribe('draftsList', {
limit: Number(Session.get('draftsLimit'))
}),
Meteor.subscribe('comments', {
postId: this.params._id
}, {
limit: Number(Session.get('commentLimit'))
}),
Meteor.subscribe('answers', {
postId: this.params._id
}, {
limit: Number(Session.get('answerLimit'))
})
];
},
data: function() {
return Posts.findOne({_id:this.params._id});
},
});
尝试在您的出版物中删除针对 this.userId
的 check
,您无需检查此 属性 有效性,因为 Meteor 已经为您完成了。
Meteor.publish('draftsList', function (options) {
check(options, {
limit: Number
});
var drafts = Drafts.find(this.userId, options);
return drafts;
});
您在您的路线中订阅了两次 draftsList
。第一个订阅没有任何参数,这将使 options
成为 undefined
而不是对象。只需删除第一个订阅,问题就会消失。
另请注意,在这种情况下,将 check
用于 this.userId
可能有效,但如果您在路线中使用 waitOn
,则可能会导致问题。当 this.userId
在需要经过身份验证的客户端的发布者中 undefined
时,普遍接受的模式是 return []
或 this.ready()
。