Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodump and mongorestore; field not found

I'm trying to dump a database from another server (this works fine), then restore it on a new server (this does not work fine).

I first run:

mongodump --host -d

This creates a folder dump/db which contains all of the bson documents.

Then in the dump folder, I'm running:

mongorestore -d dbname db

This works and iterates through the files, but I get this error on dbname.system.users

Wed May 23 02:08:05 { key: { _id: 1 }, ns: "dbname.system.users", name: "_id_" }
Error creating index dbname.system.usersassertion: 13111 field not found, expected type 16

Any ideas how to resolve this?

like image 506
dzm Avatar asked May 23 '12 02:05

dzm


People also ask

What is Mongodump and Mongorestore?

The mongodump and mongorestore utilities work with BSON data dumps, and are useful for creating backups of small deployments. For resilient and non-disruptive backups, use a file system or block-level disk snapshot function, such as the methods described in the MongoDB Backup Methods document.

How do I get Mongorestore?

The mongorestore command is the sister command of the mongodump command. You can restore the dumps (backups) created by the mongodump command into a MongoDB instance using the mongorestore command.

Where does Mongodump write to?

The mongodump command will overwrite the existing files within the given backup folder. The default location for backups is the dump/ folder. When the WiredTiger storage engine is used in a MongoDB instance, the output will be uncompressed data.

Where is Mongorestore EXE?

The executables should be mongorestore / mongodump (Linux/macOS) or mongorestore.exe / mongodump.exe (Windows). These files are typically found in the directory where you unpacked a MongoDB distribution.


3 Answers

If it realy different versions, use --noIndexRestore option. And create all index after that.

like image 121
olebedev Avatar answered Nov 08 '22 10:11

olebedev


Any chance the source and destination are different versions?

In any case, to get around this, restore the collections individually using the -c flag to the target DB and then build the indexes afterward. The system collection is the one used for indexes, so it is fairly easy to recreate - try it last once everything else has been restore, and if it still fails you can always just recreate the relevant indexes.

like image 32
Adam Comerford Avatar answered Nov 08 '22 08:11

Adam Comerford


The issue could also caused by this bug in older versions of Mongo (In my case it was 2.0.8):

https://jira.mongodb.org/browse/SERVER-7181

Basically, you get 13111 field not found, expected type 16 error when it should actually be prompting you to enter your authentication details.

And example of how I fixed it:

root@precise64:/# mongorestore /backups/demand/ondemand.05-24-2013T114223/
connected to: 127.0.0.1
[REDACTED]
Fri May 24 11:48:15      going into namespace [test.system.indexes]
Fri May 24 11:48:15 { key: { _id: 1 }, ns: "test.system.users", name: "_id_" }
Error creating index test.system.usersassertion: 13111 field not found, expected type 16
# Error when not giving username and password

root@precise64:/# mongorestore -u fakeuser -p fakepassword /backups/demand/ondemand.05-24-2013T114223/
connected to: 127.0.0.1
[REDACTED]
Fri May 24 11:57:11 /backups/demand/ondemand.05-24-2013T114223/test/system.users.bson
Fri May 24 11:57:11      going into namespace [test.system.users]
1 objects found
# Works fine when giving username and password! :)

Hope that helps anyone who's issue doesn't get fixed by the previous 2 replies!

like image 24
Peter Souter Avatar answered Nov 08 '22 10:11

Peter Souter