Meteor does see a remote mongodb instance with MongoInternals.RemoteCollectionDriver

泪湿孤枕 提交于 2019-12-22 10:29:21

问题


I have a issue when using a remote mongodb with the new meteor 1.3

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

I put it in my collections folder like this

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

But on the client side a call like this return me : C is not defined

console.log("" + C.find().count());

So i test the same line like this in my 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());
} 

But the result is the same : C is not defined

In addition my setup is with autopublish and insecure (dev staging)

Thanks in advance for any clue.


回答1:


Ok i finally figured it out (meteor 1.3, autopublish on)!

In 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 });

After this i'm able to get values on client side

console.log("MyRemoteCollection count = " + MyRemoteCollection.find().count());

Of course it works only when collections is loaded.

'Hope it will help ;)



来源:https://stackoverflow.com/questions/36353404/meteor-does-see-a-remote-mongodb-instance-with-mongointernals-remotecollectiondr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!