问题
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