Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor确实看到了一个带有MongoInternals.RemoteCollectionDriver的远程mongodb实例_Mongodb_Meteor - Fatal编程技术网

Meteor确实看到了一个带有MongoInternals.RemoteCollectionDriver的远程mongodb实例

Meteor确实看到了一个带有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中测试

我有一个问题,当使用远程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中测试相同的行:

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());