Meteor确实看到了MongoInternals.RemoteCollectionDriver的远程mongodb实例

时间:2016-04-01 10:01:36

标签: mongodb meteor

使用带有新流星1.3的远程mongodb时出现问题

var d = new MongoInternals.RemoteCollectionDriver("<mongo url>");
C = new Mongo.Collection("<collection name>", { _driver: d });

我把它放在我的集合文件夹中,就像这样

if(Meteor.isServer){
    var driver = new MongoInternals.RemoteCollectionDriver("mongodb://user:password@localhost:27017/customCollec");
} 
C = new Mongo.Collection("customCollec", { _driver: driver });

但是在客户端这样的调用会让我回复: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未定义

另外,我的设置是自动发布和不安全(dev staging)

提前感谢任何线索。

1 个答案:

答案 0 :(得分:2)

好的,我终于想通了(流星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());

当然只有在加载集合时才有效。

'希望它会有所帮助;)