ReferenceError: ShardingTest is not defined


Following the MongoDB Definitive Guide on chapter 14, I’m trying to create a Shard Cluster for testing, using the example with ShardingTest() in mongoshell, but I always get ReferenceError: ShardingTest is not defined.

My previous command was just mongosh --nodb --norc.

I can’t find almost no information about this topic.

Any help would be much appreciated.

Thank you!

Welcome to the MongoDB Community @Luis_Santos1 !

The ShardingTest() command is only available in the legacy mongo shell, which has been deprecated as of the MongoDB 6.0 server release. The mongo shell test commands were created for MongoDB server test cases, so you won’t find a lot of end user documentation. Since you are using the new MongoDB Shell (mongosh), test commands are not available.

I recommend trying out mlaunch (part of the mtools Python script collection) as a more straightforward tool for standing up local test clusters. Alternatively you could download an older MongoDB server package (5.0 or earlier) for your O/S which still has the legacy mongo shell.

I use mtools for all my own local testing.


Thank you very much Stennie!

I have installed mtools, but I can’t seem to get it going…

I’m trying the commands in CMD/Powershell but it’s not working -

The term ‘mlaunch’ is not recognized as the name of a cmdlet, function, script file, or operable program.

How or where do I run these commands?

Hi @Luis_Santos1,

I don’t have a Windows environment handy to test with, but you can list all files for a Python package installed via pip3 with:

$ pip3 show -f mtools

In my output on macOS the Location: value shows where all the package files are installed and executable scripts show a relative path from this Location (eg ../../../bin/mlaunch).


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.