We backed up mongodb data using mongodump. When we tried to restore the data using mongorestore, sometimes we get this error - : insertion error: not master. Our logic has two retries if there are errors in the first attempt. At the end, we found that this error shows for a particular collection’s restore in all three attempts. I read online posts, people pointed out this error is usually due to the write operation on the secondary. But if that is the cause, how come the restore operations on other collections were successful? I am not convinced this is the cause in our restore process. Can anyone shed lights on why mongorestore gives this error? Thanks.
The error was seen when we ran the mongorestore command.
The deployment type you are on(e.g. no of secondary, arbiters etc)
There is one primary pod and 2 secondary pods, no aribter.
The output for rs.status() or rs.conf()
We did not capture it.
The MongoDB version you are on.
4.0.25
A code snippet that would help me reproduce the error.
We observed it in restore process. One collection’s restore out of all had this problem. It’s not always reproducible. We just use mongodump https://www.mongodb.com/docs/database-tools/mongodump/ for backup, and use mongoretore mongorestore — MongoDB Manual for restoring it to another mongo instance.
Can you help me with the mongodump and mongorestore command that you are using.
See above
Finally, could you confirm if there is any operation performed on the configuration of the replica set while performing the restore operation.
The MongoDB version mentioned above quiet old and was released around June 2021.
MongoDB 4.0 is no longer supported, and upgrading to a newer version can provide improved stability, bug fixes, and additional features. You can refer to the EOL Support Policies for more information on MongoDB versions and their support status.
However, based on the error message, it appears that you are connected to a secondary node that cannot accept write operations. I would suggest verifying the current primary node and then trying the mongorestore operation again.
Also please let us know if you are still seeing the issue consistently after the upgrade.