从Iron Router查询数据库时抛出异常

时间:2016-02-20 11:48:39

标签: meteor iron-router

Meteor 1.2.1和Iron Router 1.0.12有点奇怪。

Router.route('/news/:_id', function() {
    this.render('l_basic');
    console.log (newsCollection.findOne().title);
});

这很完美。我在控制台上得到了我上一篇文章的标题。

但也有一个不需要的例外。无论我在哪里放置数据库查询:进入主路由器功能,到onAfterAction或任何其他钩子。没关系,如果我用if (this.ready())包围它。

如果我评论console.log语句,则不会出现异常。

这是我在控制台中得到的。我完全打破了我的脑袋,试图找出这里发生了什么。

Exception in callback of async function: http://localhost:3000/app/both/router.js?4bb8a45e172aaff7cfe3c5a6bff0f87a62d217d0:17:59
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:418:35
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
onRerun@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:515:13
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:418:35
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
onRun@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:499:15
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:418:35
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
dispatch@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:442:7
_runRoute@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:538:17
dispatch@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:848:27
route@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:705:19
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:418:35
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:365:18
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
dispatch@http://localhost:3000/packages/iron_middleware-stack.js?3370bd57ef7b310cca3f5dddb11b77fafdcfc1eb:442:7
http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:385:21
_compute@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
Computation@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:237:18
autorun@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:588:34
http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:383:17
nonreactive@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:13
dispatch@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:382:19
dispatch@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:1692:22
onLocationChange@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:1776:33
_compute@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
Computation@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:237:18
autorun@http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:588:34
start@http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:1769:43
http://localhost:3000/packages/iron_router.js?c564289eeaa191561eba900052037432ebfcbe4a:972:21
withValue@http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:971:21
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:428:54
http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:27
onGlobalMessage@http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:365:23

2 个答案:

答案 0 :(得分:2)

以下是有关管理Iron Router订阅的helpful documentation

我非常确定您的WHERE clause此时正在返回findOne(),这意味着您的findOne()。标题将引发异常。在查询数据之前,您需要使用undefined准备订阅。

答案 1 :(得分:0)

感谢Stephen Woods,我发现我的初始代码只是因为反应性而打印了异常和标题。我所要做的就是等待铁的订阅:路由器。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?OldStore\.com$ [NC]
RewriteRule ^(.*)$ http://NewStore/catalog/$1 [R=301,L]