Bash Meteor:在应用程序中执行Meteor mongo并获取所有集合名称

Bash Meteor:在应用程序中执行Meteor mongo并获取所有集合名称,bash,mongodb,shell,meteor,Bash,Mongodb,Shell,Meteor,我正在尝试连接meteor应用程序中的本地mongodb服务器,以便在服务器端功能中获取所有集合的列表 以下命令变量执行并返回 /Users/myProject/.meteor/local/build/programs/server 现在我想执行commandWanted变量,目的是检索所有mongo db集合的列表 server.js var Future = Meteor.npmRequire("fibers/future"); var exec = Npm.require('child_

我正在尝试连接meteor应用程序中的本地mongodb服务器,以便在服务器端功能中获取所有集合的列表

以下
命令
变量执行并返回

/Users/myProject/.meteor/local/build/programs/server
现在我想执行
commandWanted
变量,目的是检索所有mongo db集合的列表

server.js

var Future = Meteor.npmRequire("fibers/future");
var exec = Npm.require('child_process').exec;


function shell() {
    var future = new Future();
    var command = "pwd";
    var commandWanted = "meteor mongo" + "db.getCollectionNames()";
    exec(commandWanted, function(error,stdout,stderr){
            if (error) {
                    console.log(error);
                    throw new Meteor.Error(500, "failed");
            }
            console.log(stdout.toString());
            future.return(stdout.toString());
    });
    return future.wait();
}


shell();

使用RemoteCollectionDriver访问先前存在的MongoDB集合

var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.collectionNames(function(err, collections) {
    if (err) throw err;
    console.log(collections);
});

// for commands not natively supported by the driver - http://docs.mongodb.org/manual/reference/command/
db.command({profile: 1}, function(error, result) {
    if (error) throw error;
    if (result.errmsg)
        console.error('Error calling native command:', result.errmsg);
    else
        console.log(result);
});
要实现此服务器端,可以遵循以下异步模式:

var shell = function () {
    var Future = Npm.require('fibers/future'),
        future = new Future(),
        db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;

    db.collectionNames( 
        function(error, results) {
            if (err) throw new Meteor.Error(500, "failed");
            future.return(results);
        }
    );
    return future.wait();
};

使用RemoteCollectionDriver访问先前存在的MongoDB集合

var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.collectionNames(function(err, collections) {
    if (err) throw err;
    console.log(collections);
});

// for commands not natively supported by the driver - http://docs.mongodb.org/manual/reference/command/
db.command({profile: 1}, function(error, result) {
    if (error) throw error;
    if (result.errmsg)
        console.error('Error calling native command:', result.errmsg);
    else
        console.log(result);
});
要实现此服务器端,可以遵循以下异步模式:

var shell = function () {
    var Future = Npm.require('fibers/future'),
        future = new Future(),
        db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;

    db.collectionNames( 
        function(error, results) {
            if (err) throw new Meteor.Error(500, "failed");
            future.return(results);
        }
    );
    return future.wait();
};