Mongodb 如何在meteor中重命名集合?

Mongodb 如何在meteor中重命名集合?,mongodb,meteor,Mongodb,Meteor,我想从代码中重命名集合,而不是从shell,但我找不到命令, 我知道 但是它只来自shell,因为Meteor构建在NodeJS之上,所以您可以使用任何NodeJS包和API。在您的情况下,可以在代码中使用bash命令运行rename命令 Gentlenode的创始人朱利安(Julien)给出并撰写了这篇文章,以更详细地描述这一过程。为了您的方便,请将其复制到下面 exec = Npm.require('child_process').exec; child = exec('ls -la',

我想从代码中重命名集合,而不是从shell,但我找不到命令, 我知道


但是它只来自shell

,因为Meteor构建在NodeJS之上,所以您可以使用任何NodeJS包和API。在您的情况下,可以在代码中使用bash命令运行rename命令

Gentlenode的创始人朱利安(Julien)给出并撰写了这篇文章,以更详细地描述这一过程。为了您的方便,请将其复制到下面

exec = Npm.require('child_process').exec;

child = exec('ls -la', function(error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);

  if(error !== null) {
    console.log('exec error: ' + error);
  }
}

// More concisely
runCommand = function (error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);

  if(error !== null) {
    console.log('exec error: ' + error);
  }
}

exec("ls -la", runCommand);

在代码中,可以使用
mongo--eval“yourcommand()”
。更多选项可在中找到。(如果您已经在您的机器上使用MongoDB,而不是Meteor提供的MongoDB,这将起作用。)

但是mongo是插入Meteor的吗?我必须输入“meteor mongo”才能访问shell mongo,并且--eval不退出。我错过了什么?抱歉我的英语不好:pMy解决方案并不完美,因为它要求您运行本地MongoDB,而不是Meteor提供的MongoDB,这是不同的(如果我错了,任何人都可以纠正我)。您可以看到如何运行自己的Mongo
exec = Npm.require('child_process').exec;

child = exec('ls -la', function(error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);

  if(error !== null) {
    console.log('exec error: ' + error);
  }
}

// More concisely
runCommand = function (error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);

  if(error !== null) {
    console.log('exec error: ' + error);
  }
}

exec("ls -la", runCommand);