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.
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 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).