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

    • Platforms 2016-11-21, Platforms 2017-01-23
    • v3.4

      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”}})
      

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

              Created:
              Updated:
              Resolved: