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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.4.1, 3.5.2
    • Component/s: mongodump, mongorestore
    • Labels:
      None
    • Backport Requested:
      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

              Assignee:
              matt.cotter Matt Cotter
              Reporter:
              tess.avitabile Tess Avitabile
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: