Mongodb Not Restarting with Collections, WiredTiger.wt may be corrupt

mongodbmongodb-3.2wiredtiger

I believe my MongoDB did not have a clean shutdown. I am able to restart it in a new location which doesn't have all of my collections. If I try to repair or start it in the old location, it gives the following error:

[ec2-user@ip-172-31-30-192 tmp]$ mongod --repair --dbpath /data

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] MongoDB starting : pid=31865 port=27017 dbpath=/data 64-bit host=ip-172-31-30-192

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] db version v3.2.16

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] git version: 056bf45128114e44c5358c7a8776fb582363e094

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] allocator: tcmalloc

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] modules: none

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] build environment:

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] distmod: amazon

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] distarch: x86_64

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] target_arch: x86_64

2017-08-20T16:20:30.951+0000 I CONTROL [initandlisten] options: { repair: true, storage: { dbPath: "/data" }

} 2017-08-20T16:20:30.972+0000 I - [initandlisten] Detected data files in /data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.

2017-08-20T16:20:30.972+0000 I STORAGE [initandlisten] Detected WT journal files. Running recovery from last checkpoint.

2017-08-20T16:20:30.972+0000 I STORAGE [initandlisten] journal to nojournal transition config: create,cache_size=17G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),

2017-08-20T16:20:30.981+0000 E STORAGE [initandlisten] WiredTiger (-31802) [1503246030:981472][31865:0x7f6ad1d9fd80], file:WiredTiger.wt, connection: unable to read root page from file:WiredTiger.wt: WT_ERROR: non-specific WiredTiger error

2017-08-20T16:20:30.981+0000 E STORAGE [initandlisten] WiredTiger (0) [1503246030:981530][31865:0x7f6ad1d9fd80], file:WiredTiger.wt, connection: WiredTiger has failed to open its metadata

2017-08-20T16:20:30.981+0000 E STORAGE [initandlisten] WiredTiger (0) [1503246030:981548][31865:0x7f6ad1d9fd80], file:WiredTiger.wt, connection: This may be due to the database files being encrypted, being from an older version or due to corruption on disk

2017-08-20T16:20:30.981+0000 E STORAGE [initandlisten] WiredTiger (0) [1503246030:981564][31865:0x7f6ad1d9fd80], file:WiredTiger.wt, connection: You should confirm that you have opened the database with the correct options including all encryption and compression options

2017-08-20T16:20:30.981+0000 I - [initandlisten] Assertion: 28718:-31802: WT_ERROR: non-specific WiredTiger error

2017-08-20T16:20:30.982+0000 I STORAGE [initandlisten] exception in initAndListen: 28718 -31802: WT_ERROR: non-specific WiredTiger error, terminating

2017-08-20T16:20:30.982+0000 I CONTROL [initandlisten] dbexit: rc: 100

Is there a way to fix my wiredtiger.wt file or move my collections and indexes from the old location into the new location?

Best Answer

There's now an official repair option that worked for me after a sudden computer shutdown https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/

  1. Create a backup copy of the data files in the --dbpath
  2. Start mongod with --repair

mongod --dbpath /data/db --repair

Upon completion, the dbpath should contain the repaired data files and an empty mongod.lock

The collections were repaired without data loss.