【发布时间】:2026-02-04 02:50:02
【问题描述】:
我正在尝试使用流星中的现有集合:
我试过了
SET MONGO_URL="mongodb://localhost:27017/test2" meteor
但这没有用。我从www.angular-meteor.com修改了示例:
server.js
if (Meteor.isServer) {
Meteor.startup(function () {
var myDatabase = new MongoInternals.RemoteCollectionDriver("mongodb://127.0.0.1:27017/test2");
MyCollection = new Mongo.Collection("mydata", { _driver: myDatabase });
});
}
app.js
if (Meteor.isClient) {
angular.module('socially', ['angular-meteor']);
angular.module('socially').directive('partiesList', function() {
return {
restrict: 'E',
templateUrl: 'parties-list.html',
controllerAs: 'partiesList',
controller: function($scope, $reactive) {
$reactive(this).attach($scope);
this.helpers({
parties: () => {
return MyCollection.findOne({});
}
});
}
}
});
}
party-list.html
<ul>
<li ng-repeat="party in partiesList.parties">
{{MyCollection.Date}}
<p>{{MyCollection.name}}</p>
</li>
</ul>
main.html
<parties-list></parties-list>
任何想法我做错了什么?我在Cannot connect to alternate Mongo DB in Meteor App 找到了答案,但仍然试图让<ul> 显示一些东西,现在它没有显示任何东西而且我的页面是空的。
【问题讨论】:
-
你能注释掉那个 isServer 块并试试这个:% MONGO_URL=mongodb://localhost:27017/test2 meteor
-
@Brendan Turner 试过了,但没用
-
错误信息? db 'test2' 是否已创建?
-
没有错误。是的 test2 db 存在于带有 mydata 集合的本地 mongodb 中。但总的来说,这是一个正确的方法吗?或者环境变量也应该起作用?
-
env 是我在生产中使用我的应用程序的方式。不知道为什么它不起作用。您是否使用过 mongo shell 来确保 test2 上有集合/文档?