Fabio Bracht
Fabio Bracht

Reputation: 423

Error in mongodb: "getFile(): bad file number value (corrupt db?): run repair"

After my last Meteor upgrade my database became corrupted. First it started with this error message when I tried to create a new user (we're using meteor-accounts):

getFile(): bad file number value (corrupt db?): run repair

Then I saw in another question that I should run db.repairDatabase() but, although mongo shell said that the database was now ok, it didn't really work. The error message above was still showing up.

So I read something about corrupted indexes and dropped the indexes in the users collections and this obviously just made everything worse. Now I have two users with the same email address and Meteor doesn't start anymore:

MongoError: E11000 duplicate key error index: meteor.users.$emails.address_1  dup key: { : "[email protected]" }

When I try to remove one of these users, the original error shows up again:

meteor:PRIMARY> db.users.remove({ _id: "cAtu2XsEXTbqL2Wvx"})
getFile(): bad file number value (corrupt db?): run repair`

Fortunately we're still on the development phase and we can just drop the whole database and start over, but this has made me really insecure about running Meteor on production environment. Is there any way to fix a database in this state?

Upvotes: 4

Views: 679

Answers (1)

wdberkeley
wdberkeley

Reputation: 11671

You can run db.repairDatabase to try to repair the data files - but read the linked page first for details and warnings. Make sure you run with journaling on if you didn't have it on before and, at least for production, run a replica set. Normally, in this situation it'd be preferable to resync from another replica set member or restore a backup rather than repair. You can find more information about data recovery in this article from the MongoDB Manual.

Upvotes: 2

Related Questions