Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2583

Unhelpful mongorestore error "don't know what to do with file"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: No version
    • Component/s: mongorestore
    • Labels:
      None
    • Environment:
      Ubuntu 20

      Description

      I genuinely can't figure out how to mongorestore a database using the --uri switch, and I wish the error output by mongorestore were more helpful. I'll list the commands below, along my reaction at several points. The goal was to mongodump mydb using the --uri parameter, then mongorestore to a development database. I tried using the --archive option, which failed (TOOLS-2580).

      $ rm -rf dump
      $ mongodump --uri=$MONGO_PROD_READONLY
      2020-05-12T00:14:16.286-0700 writing mydb.users to
      2020-05-12T00:14:16.651-0700 writing mydb.posts to
      2020-05-12T00:14:16.709-0700 done dumping mydb.users (384 documents)
      2020-05-12T00:14:16.838-0700 done dumping mydb.posts (59 documents)
      $ ls -al dump/mydb/
      total 604
      drwxrwxr-x 2 dandv dandv 4096 May 12 00:14 .
      drwxrwxr-x 3 dandv dandv 4096 May 12 00:14 ..
      rw-rw-r- 1 dandv dandv 511991 May 12 00:14 users.bson
      rw-rw-r- 1 dandv dandv 739 May 12 00:14 users.metadata.json
      rw-rw-r- 1 dandv dandv 86685 May 12 00:14 posts.bson
      rw-rw-r- 1 dandv dandv 623 May 12 00:14 posts.metadata.json
      $ mongorestore --uri=$MONGO_DEV dump/mydb/
      2020-05-12T00:14:40.050-0700 preparing collections to restore from
      2020-05-12T00:14:40.050-0700 don't know what to do with file "dump/mydb/users.bson", skipping...
      2020-05-12T00:14:40.050-0700 don't know what to do with file "dump/mydb/users.metadata.json", skipping...
      2020-05-12T00:14:40.050-0700 don't know what to do with file "dump/mydb/posts.bson", skipping...
      2020-05-12T00:14:40.050-0700 don't know what to do with file "dump/mydb/posts.metadata.json", skipping...
      2020-05-12T00:14:40.050-0700 0 document(s) restored successfully. 0 document(s) failed to restore.

      Why did mongorestore fail here? I passed a URI and the path to the dump directory. What was there to do with the .bson files other than import them?

      Let's try a specific file anyway:

      $ mongorestore --uri=$MONGO_DEV dump/mydb/users.bson
      2020-05-12T00:15:13.402-0700 checking for collection data in dump/mydb/users.bson
      2020-05-12T00:15:13.448-0700 finished restoring mydb.users (0 documents, 0 failures)
      2020-05-12T00:15:13.448-0700 Failed: mydb.users: error reading database: (AtlasError) user is not allowed to do action [listCollections] on [mydb.]
      2020-05-12T00:15:13.448-0700 0 document(s) restored successfully. 0 document(s) failed to restore.

      Why did mongorestore try to list collections in mydb? The target --uri refers to a different database:

      $ echo $MONGO_DEV
      mongodb+srv://mydb-dev:[PASSWORD]@mydb-start-kpwtc.mongodb.net/mydb-dev

      Maybe it reads the database name from the dump directory? Let's rename it:

      $ mv dump/mydb/ dump/mydb-dev
      $ mongorestore --uri=$MONGO_DEV --drop dump/mydb-dev/
      2020-05-12T00:15:56.433-0700 preparing collections to restore from
      2020-05-12T00:15:56.434-0700 don't know what to do with file "dump/mydb-dev/users.bson", skipping...
      2020-05-12T00:15:56.434-0700 don't know what to do with file "dump/mydb-dev/users.metadata.json", skipping...
      2020-05-12T00:15:56.434-0700 don't know what to do with file "dump/mydb-dev/posts.bson", skipping...
      2020-05-12T00:15:56.434-0700 don't know what to do with file "dump/mydb-dev/posts.metadata.json", skipping...
      2020-05-12T00:15:56.434-0700 0 document(s) restored successfully. 0 document(s) failed to restore.

      Nope, that didn't work either. How do people do this?

      Let's just omit the directory, which is wrong if there are multiple dumps:

      $ mongorestore --uri=$MONGO_DEV --drop
      2020-05-12T00:16:37.621-0700 using default 'dump' directory
      2020-05-12T00:16:37.622-0700 preparing collections to restore from
      2020-05-12T00:16:37.721-0700 reading metadata for mydb-dev.users from dump/mydb-dev/users.metadata.json
      2020-05-12T00:16:37.786-0700 restoring mydb-dev.users from dump/mydb-dev/users.bson
      2020-05-12T00:16:38.177-0700 reading metadata for mydb-dev.posts from dump/mydb-dev/posts.metadata.json
      2020-05-12T00:16:38.195-0700 restoring indexes for collection mydb-dev.users from metadata
      2020-05-12T00:16:38.239-0700 restoring mydb-dev.posts from dump/mydb-dev/posts.bson
      2020-05-12T00:16:38.293-0700 finished restoring mydb-dev.users (384 documents, 0 failures)
      2020-05-12T00:16:38.413-0700 restoring indexes for collection mydb-dev.posts from metadata
      2020-05-12T00:16:38.487-0700 finished restoring mydb-dev.posts (59 documents, 0 failures)
      2020-05-12T00:16:38.487-0700 443 document(s) restored successfully. 0 document(s) failed to restore.
      $

      Well that worked, with the same dump directory, but it doesn't make any sense why specifying that dump directory didn't work.

        Attachments

          Activity

            People

            Assignee:
            tim.fogarty Tim Fogarty
            Reporter:
            dandv Dan Dascalescu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: