Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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 Mongo集合名称检索为Javascript数组?_Javascript_Mongodb_Meteor - Fatal编程技术网

如何将所有Meteor Mongo集合名称检索为Javascript数组?

如何将所有Meteor Mongo集合名称检索为Javascript数组?,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我尝试使用: MongoInternals.defaultRemoteCollectionDriver().mongo.db.listCollections() 为了获取meteor数据库中的所有集合名称,但它返回了一个很长的JSON,在其中我找不到纯集合名称。(见附图) 如何以以下格式获取meteor集合名称: ["test1", "test2", "users"...] 好的,这是工作代码,谢谢@PaulS db = MongoInternals.defaultRemoteCollec

我尝试使用:

MongoInternals.defaultRemoteCollectionDriver().mongo.db.listCollections()
为了获取meteor数据库中的所有集合名称,但它返回了一个很长的JSON,在其中我找不到纯集合名称。(见附图)

如何以以下格式获取meteor集合名称:

["test1", "test2", "users"...]

好的,这是工作代码,谢谢@PaulS

db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
collections = db.listCollections();

collections.each(function(n, collection){
  if(collection){
    console.log( collection.name );
  }
});

listCollections
返回一个
MongoCollection
,调用
.getNamespace()
以获取名称。请注意,您看到的返回值不是JSON,而是控制台对对象的解释,因此出现了
[Function]
@PaulS等项。感谢您的澄清,我将根据这些信息实现代码。