流星:列出服务器上的所有集合 [英] Meteor: List all collections on the server
问题描述
我无法列出服务器上Meteor应用程序中创建的所有集合.
I am unable to list all the collections created within the Meteor app on the server.
收藏集位于... /root/packages/lib/collectionName.js
collectionName的操作成功.但是,由于我有很多集合,因此我需要一个函数来检索创建的集合的所有名称.
Operations to collectionName succeeds. However, as I have many collections, I require a function to retrieve all the names of the collections created.
在服务器功能中 加载完集合后,方法将执行以下功能;
In a server function after the collections have been loaded, a method executes the following function;
MyCollection = Mongo.Collection.getAll();
console.log(MyCollection);
[ { name: 'users',
instance:
{ _makeNewID: [Function],
_transform: null,
_connection: [Object],
_collection: [Object],
_name: 'users',
_driver: [Object],
_restricted: true,
_insecure: undefined,
_validators: [Object],
_prefix: '/users/' },
options: undefined },
{ name: 'MeteorToys/Impersonate',
instance:
{ _makeNewID: [Function],
....
Meteor创建的用户集合在那里.但是创建的所有集合(其中3个都带有Collection2程序包)都不会显示.
The user collection created by Meteor is there. But all the collections created, 3 of which are with Collection2 package do not show.
我想念什么?
如果我需要child_process库并执行一系列命令,将会有什么含义.流星mongo" ..."db.getCollectionNames()"?
What are the implications if I require the child_process library and execute a series of commands.. "meteor mongo"... "db.getCollectionNames()"?
推荐答案
要列出服务器上的所有集合,请使用RemoteCollectionDriver访问预先存在的MongoDB集合.要实现此服务器端,您可以遵循以下异步模式:
To list all collections on the server, use the RemoteCollectionDriver to access preexisting MongoDB Collections. To implement this server side, you could follow this asynchronous pattern:
var shell = function () {
var Future = Npm.require('fibers/future'),
future = new Future(),
db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.collectionNames(
function(error, results) {
if (error) throw new Meteor.Error(500, "failed");
future.return(results);
}
);
return future.wait();
};
这篇关于流星:列出服务器上的所有集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!