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应用程序访问现有MongoDB集合_Mongodb_Meteor_Collectionfs - Fatal编程技术网

从meteor应用程序访问现有MongoDB集合

从meteor应用程序访问现有MongoDB集合,mongodb,meteor,collectionfs,Mongodb,Meteor,Collectionfs,在我的MongoDB中,我有一个从服务器端创建和填充的集合,称为“fs.files”(它是一个gridFS集合) 在我的meteor应用程序中,有没有一种方法可以声明一个全局变量,它可以简单地从这个数据库中获取信息 我试过了 PDFs = new Mongo.Collection("fs.files"); PDFs = new FS.Collection("fs.files", { stores: [new FS.Store.FileSystem("fsfiles", {path: "

在我的MongoDB中,我有一个从服务器端创建和填充的集合,称为“fs.files”(它是一个gridFS集合)

在我的meteor应用程序中,有没有一种方法可以声明一个全局变量,它可以简单地从这个数据库中获取信息

我试过了

PDFs = new Mongo.Collection("fs.files");

PDFs = new FS.Collection("fs.files", {
    stores: [new FS.Store.FileSystem("fsfiles", {path: "./reports"})]
});
当我执行PDFs.find().fetch()时,它们都将返回一个空数组


问题是,我不想创建新集合。我只是想访问一个现有的数据库,因为我不从客户端创建这个数据库

你的方法应该有效。您可能忘记了在服务器上发布此集合并在客户端上订阅它

服务器:

Meteor.publish('myPDFs',function(){
  return PDFs.find();
});
客户:

Meteor.subscribe('myPDFs');

你确定你的gridFS集合是同一个数据库吗?meteor默认数据库为“meteor”,gridFS maya可能会将数据存储在自己的数据库中。使用mongo客户端检查是否有其他集合。