如何将所有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等项。感谢您的澄清,我将根据这些信息实现代码。