Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-7573

Clarify the behavior of mongorestore --archive with --db or --collection options

      https://docs.mongodb.org/manual/reference/program/mongorestore/#cmdoption--db

      Specifies a database for mongorestore to restore data into. If the database does not exist, mongorestore creates the database. If you do not specify a <db>, mongorestore creates new databases that correspond to the databases where data originated and data may be overwritten. Use this option to restore data into a MongoDB instance that already has data.

      --db does not control which BSON files mongorestore restores. You must use the mongorestore path option to limit that restored data.

      However, as noted at https://docs.mongodb.org/manual/reference/program/mongorestore/#restore-a-database-from-an-archive-file

      --db is used to select which database is restored from the archive.

      If --db or --collection specifies a database or collection not contained in the dump archive no data will be restored:

      mongodump --archive=test.archive --db test --collection foo
      2016-04-04T16:44:44.555-0400	writing test.foo to archive 'test.archive'
      2016-04-04T16:44:44.555-0400	done dumping test.foo (1 document)
      
      mongorestore --archive=test.archive --db test --collection bar
      2016-04-04T16:44:50.917-0400	setting number of parallel collections to number of parallel collections in archive (8)
      2016-04-04T16:44:50.942-0400	creating intents for archive
      2016-04-04T16:44:50.986-0400	done
      
      mongorestore --archive=test.archive --db test --collection foo
      2016-04-04T16:44:56.531-0400	setting number of parallel collections to number of parallel collections in archive (8)
      2016-04-04T16:44:56.556-0400	creating intents for archive
      2016-04-04T16:44:56.619-0400	reading metadata for test.foo from archive 'test.archive'
      2016-04-04T16:44:56.619-0400	restoring test.foo from archive 'test.archive'
      2016-04-04T16:44:56.626-0400	error: E11000 duplicate key error collection: test.foo index: _id_ dup key: { : ObjectId('5702d13cd25b3ef5b9fe55b3') }
      2016-04-04T16:44:56.928-0400	restoring indexes for collection test.foo from metadata
      2016-04-04T16:44:56.928-0400	finished restoring test.foo (1 document)
      2016-04-04T16:44:56.928-0400	done
      

      I think this distinction should be highlighted as part of the description of the --db option quoted above.

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              4 years, 42 weeks ago