Meteor确实看到了一个带有MongoInternals.RemoteCollectionDriver的远程mongodb实例
我有一个问题,当使用远程mongodb与新的流星1.3Meteor确实看到了一个带有MongoInternals.RemoteCollectionDriver的远程mongodb实例,mongodb,meteor,Mongodb,Meteor,我有一个问题,当使用远程mongodb与新的流星1.3 var d = new MongoInternals.RemoteCollectionDriver("<mongo url>"); C = new Mongo.Collection("<collection name>", { _driver: d }); 但在客户端,这样的调用返回我:C未定义 console.log("" + C.find().count()); 所以我在我的collections.js中测试
var d = new MongoInternals.RemoteCollectionDriver("<mongo url>");
C = new Mongo.Collection("<collection name>", { _driver: d });
但在客户端,这样的调用返回我:C
未定义
console.log("" + C.find().count());
所以我在我的collections.js中测试相同的行:
if(Meteor.isServer){
var driver = new MongoInternals.RemoteCollectionDriver("mongodb://user:password@localhost:27017/customCollec");
C = new Mongo.Collection("customCollec", { _driver: driver });
console.log("" + C.find().count());
}
但结果是一样的:C
没有定义
此外,我的设置带有自动发布和不安全(开发人员登台)
提前感谢您提供的任何线索。好的,我终于找到了答案(meteor 1.3,自动发布开启) 在lib/collections.js中
var database;
if(Meteor.isServer){
console.log("On collections ");
database = new MongoInternals.RemoteCollectionDriver("mongodb://user:password@0.0.0.0:27017/db_name");
}
MyRemoteCollection = new Mongo.Collection('db_name', { _driver: database });
在此之后,我能够在客户端获得值
console.log("MyRemoteCollection count = " + MyRemoteCollection.find().count());
当然,它仅在加载集合时才起作用
“希望能有所帮助;”
console.log("MyRemoteCollection count = " + MyRemoteCollection.find().count());