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

Running mongodump then mongorestore should restore the _id index with its exact original spec

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.4.1, 3.5.2
    • mongodump, mongorestore
    • None
    • Platforms 2016-11-21, Platforms 2017-01-23
    • v3.4

    Description

      mongodump can get the _id index spec from the listCollections output:

      > db.runCommand({listCollections: 1})
      {
      	"cursor" : {
      		"id" : NumberLong(0),
      		"ns" : "test.$cmd.listCollections",
      		"firstBatch" : [
      			{
      				"name" : "c",
      				"type" : "collection",
      				"options" : {
      					
      				},
      				"info" : {
      					"readOnly" : false
      				}
      				“idIndex”: {
      					"v" : 1,
      					"key" : {
      						"_id" : 1
      						},
      					"name" : "_id_",
      					"ns" : "test.c"
      				}
      			},
      ]	
      }
      }
      

      Note that the idIndex field will not be present for views or for collections without an _id index (i.e. autoIndexId: false).
      mongorestore can specify the spec for the _id index in the create command:

      > db.runCommand({create: "c", 
      idIndex: {v: 1, key: {_id: 1}, name: “_id_”, ns: “test.c”}})
      

      Attachments

        Issue Links

          Activity

            People

              matt.cotter Matt Cotter
              tess.avitabile@mongodb.com Tess Avitabile (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: