Mongodb 在ShardingTest中设置小文件

Mongodb 在ShardingTest中设置小文件,mongodb,sharding,Mongodb,Sharding,我知道有一个ShardingTest()对象可用于创建测试分片环境(请参阅),例如: 但是,考虑到我的测试机中的磁盘空间有限,并且在使用上述命令时出现“日志文件可用空间不足”错误,我想设置smallfiles选项。我尝试过以下方法,但没有成功: cluster = new ShardingTest({shards : 3, rs : false, smallfiles: true}) 如何为分片测试启用smallfiles?谢谢 有关ShardingTest()调用模式的详细说明,请参见 例如

我知道有一个ShardingTest()对象可用于创建测试分片环境(请参阅),例如:

但是,考虑到我的测试机中的磁盘空间有限,并且在使用上述命令时出现“日志文件可用空间不足”错误,我想设置smallfiles选项。我尝试过以下方法,但没有成功:

cluster = new ShardingTest({shards : 3, rs : false, smallfiles: true})

如何为分片测试启用smallfiles?谢谢

有关
ShardingTest()
调用模式的详细说明,请参见

例如,您可以为两个碎片设置
smallFiles
,如下所示:

cluster = new ShardingTest({shards: {d0:{smallfiles:''}, d1:{smallfiles:''}}})

确定如何使用MongoDB shell命令的一个好方法是在shell中键入不带括号的命令,而不是运行它,它将打印命令的源代码。所以如果你跑

ShardingTest
在命令提示下,您将看到所有源代码。在第30行,您将看到以下评论:

    // Allow specifying options like :
    // { mongos : [ { noprealloc : "" } ], config : [ { smallfiles : "" } ], shards : { rs : true, d : true } }
这为您提供了正确的语法来传递mongos、config和shard的配置参数(适用于所有shard的非复制集mongods)。也就是说,不要为传入对象的碎片指定数字。进一步挖掘代码:

else if( isObject( numShards ) ){
            tempCount = 0;
            for( var i in numShards ) {
                otherParams[ i ] = numShards[i];
                tempCount++;
            }

            numShards = tempCount;
这将获取一个对象,并使用对象中的子文档作为每个碎片的选项参数。使用您的示例,这将导致:

cluster = new ShardingTest({shards : {d0:{smallfiles:''}, d1:{smallfiles:''}, d2:{smallfiles:''}}})
从我看到的输出中,它以--smallfiles开始碎片:

shell: started program mongod --port 30000 --dbpath /data/db/test0 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30001 --dbpath /data/db/test1 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30002 --dbpath /data/db/test2 --smallfiles --setParameter enableTestCommands=1
或者,由于您现在已经有了源代码,您可以修改javascript以在默认情况下传入SmallFile

shell: started program mongod --port 30000 --dbpath /data/db/test0 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30001 --dbpath /data/db/test1 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30002 --dbpath /data/db/test2 --smallfiles --setParameter enableTestCommands=1