I’m trying to test a simple sharded MongoDB cluster configuration, with MongoDB 4.4.6 on Ubuntu 20.04, installed from the official mongodb-org package. I ran the following steps:
-
Start up shard servers:
mkdir ./mongo1 ./mongo2
mongod --shardsvr --dbpath ./mongo1 --port 27014
mongod --shardsvr --dbpath ./mongo2 --port 27015
-
Start up config server:
mkdir ./mongoconfig
mongod --configsvr --replSet configSet --dbpath ./mongoconfig --port 27016
-
Connected to the config server using
mongo localhost:27016
and ran the following command to initiate the (single-node) config server cluster:
rs.initiate({ _id: 'configSet', configsvr: true, members: [ { _id: 0, host: 'localhost:27016' } ] })
-
Start up
mongos
:
mongos --configdb configSet/localhost:27016 --port 27020
-
Connect to
mongos
in theadmin
database withmongo localhost:27020/admin
, and configure sharding servers:
sh.addShard('localhost:27014')
sh.addShard('localhost:27015')
-
Configure sharding for database
test
and collectiontest.cities
:
db.runCommand({ enablesharding : "test" })
db.runCommand({ shardcollection : "test.cities", key : {name : 1} })
-
Finally, import some test data using
mongoimport
.
The data to import is in the filecities.json
, whose content is:
cities.json:
[{"name":"Sant Julià de Lòria", "country":"AD", "timezone":"Europe/Andorra", "population":8022, "location": { "longitude":42.46372, "latitude":1.49129} }, {"name":"Pas de la Casa", "country":"AD", "timezone":"Europe/Andorra", "population":2363, "location": { "longitude":42.54277, "latitude":1.73361} }]
The import command is:
mongoimport --host localhost:27020 --db test --collection cities --type json cities.json --jsonArray
When running the import command, I get the following error:
Failed: this MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string
I also tried the following, which gives the exact same error:
mongoimport --uri "mongodb://localhost:27020/?retryWrites=false" --db test --collection cities --type json cities.json --jsonArray
What am I missing? How do I make retryable writes work in this simple sharded cluster?
Thank you.