【发布时间】:2014-12-04 23:52:34
【问题描述】:
我是流星的新手,我尝试构建一个流星应用程序,该应用程序应该在另一个 Mongo 数据库中显示数据。它自己的应用程序可以使用自己的metor数据库。所以我发现,用MongoInternals.RemoteCollectionDriver() 连接我的第二个数据库。
下一步是让它在流星教程中工作。但我没有从第二个数据库中取回任何数据。对于测试,简单的数组从我的函数中正确返回并直接放入 webapp。 .find() 中的表达式应该也可以。我在 Mongo 控制台中对其进行了测试。
如果与第二个数据库的连接位于if (Meteor.isClient) 或客户端/服务器部分之外,则会出现错误“ReferenceError: MongoInternals is not defined”。如果它在if (Meteor.isServer) 内设置,有时控制台中会出现异常:
模板助手中的异常:.
ris_sessions@http://localhost:3000/risdd_mongo.js?4fc7111851b4ed2182782e0a368b366cc4e89745:15:17 bindDataContext/http://localhost:3000/packages /blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:14
......还有更多消息
我看不到,为什么不从第二个数据库取回任何数据。
以下是来源:
Tasks = new Mongo.Collection("tasks");
//////////////////////
if (Meteor.isClient) {
Template.body.helpers({
tasks: function() {
return Tasks.find({}, {sort: {createdAt: -1 }});
}
,
s_sessions: function() {
return ris_sess.find( {},{description:1} ).fetch();
}
});
}
//////////////////////
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
var risdb_drv = new MongoInternals.RemoteCollectionDriver("mongodb://172.0.0.1:27017/ris");
var ris_sess = new Mongo.Collection("sessions", { _driver: risdb_drv });
});
}
<head>
<title>foo</title>
</head>
<body>
<div class="container">
<header>
<h1>todo list</h1>
<!-- add a FORM !-->
<form class="new-task">
<input type="text" name="text" placeholder="ad your task here" />
</form>
</header>
<ul>
{{#each tasks}}
{{>task}}
{{/each}}
{{#each ris_sessions}}
{{>ris_session}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
<template name="ris_session">
<li>{{description}}</li>
</template>
【问题讨论】:
-
也许,问题是另一个。几秒钟后,消息出现:=> Started MongoDB。 I20141206-06:48:57.548(1)?异步函数回调异常:错误:无法连接到 [172.0.0.1:27017] I20141206-06:48:57.671(1)?在 null. (/home/row/.meteor/packages/mongo/.1.0.8.qrjcjj++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/server .js:536:74)
-
您找到解决方案了吗 - 我也收到“未定义 MongoInternals”错误?