View the MongoDB. log and find the following statements in the log:
..............
Mon Mar 317: 46: 37 [conn148] assertion: 10295:GetFile (): Bad file number value (upt DB ?) : Run repair
..............
Or
Com. MongoDB. mongoexception: Bad offset: 0 accessing File:/data/dbdata/db.0-consider repairing Database
Declaration: GetFile (): incorrect file value (corrupt database ?) : Run repair
Check the MongoDB document and use the following methods to fix the problem:
First, stop the mongod service, delete MongoDB. log, and back up it.
# Rm-RF/data/MongoDB. Log
Delete MongoDB process files
# Rm-RF/MongoDB/mongod. Lock
Repair
#/Usr/local/MongoDB/bin/mongod -- repair -- dbpath/MongoDB/-- repairpath/MongoDB/repair/
If
./Mongod -- repair -- dbpath/data/dbdata -- repairpath/data/repair/-- logpath/data/dblog/mongodbrepair. log -- fork
At this time, the MongoDB process will store temporary repair database files in the/MongoDB/repair/directory. The file directory is "$ tmp_repairdatabase_0", so the directory space should be large enough.
The database in the production environment is 100 GB, and the repair takes about three and a half hours. A temporary database file of nearly 30 GB is generated in the "/MongoDB/repair/$ tmp_repairdatabase_0" directory, after the repair is completed, the temporary database files are automatically cleared.
Then enable the mongod service, check the database, and find that the read and write operations are normal. There is no error in MongoDB. log. Fix OK!
The principle is: Read the data again and write it to another database.