【问题标题】:Can ShardingTest() pass non-default dbpath to mongod?ShardingTest() 可以将非默认 dbpath 传递给 mongod 吗?
【发布时间】:2015-08-31 13:04:23
【问题描述】:

我在 OS X 10.11/15A263e 上运行 mongodb 3.0.6 (homebrew),无法通过 ShardingTest 的 js 代码指定非默认数据文件路径。

出于某种原因,我想避免弄乱 /data 中的符号链接或实际数据文件,但更重要的是,我想学习如何使该类 ShardingTest 下面的代码正常工作:

manoa:dev mike$ mongo --nodb
MongoDB shell version: 3.0.6
> var options = { shardOptions : { dbpath : "/usr/local/var/mongodb" } };
> cluster = new ShardingTest( { shards : 3 }, { other : options } );
Resetting db path '/data/db/test0'
2015-08-31T07:54:03.707-0500 E QUERY    Error: boost::filesystem::create_directory: No such file or directory: "/data/db/test0"
    at Function.MongoRunner.runMongod (src/mongo/shell/servers.js:589:13)
    at new ShardingTest (src/mongo/shell/shardingtest.js:259:36)
    at (shell):1:11 at src/mongo/shell/servers.js:589

looked over this helpful post,但我的 JS 太弱,无法从那里的帮助中概括出如何设置 dbpath 以及哪些参数将覆盖默认路径。

有人可以提出一种方法来调试此脚本或提供实际语法来将我首选的数据库路径提供给 ShardingTest 函数吗?

【问题讨论】:

    标签: javascript mongodb homebrew


    【解决方案1】:

    MongoRunner.dataPathused to construct db paths

    this.getDBPaths = function() {
        return _alldbpaths.map((path) => {
            return MongoRunner.dataPath + path;
        });
    };
    

    所以你可以将它设置为你想要的任何目录,例如:

    // don't forget the trailing slash
    MongoRunner.dataPath = '/home/your_user/data/db/'
    

    【讨论】:

      猜你喜欢
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 2014-06-08
      • 2021-06-11
      • 2022-11-02
      相关资源
      最近更新 更多