Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13875

ensureIndex of 2dsphere index breaks after upgrading to 2.6 (with the new createIndex command)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.11, 3.0.4, 3.1.3
    • Affects Version/s: 2.6.1
    • Component/s: Geo
    • Minor Change
    • ALL

      On a collection, I have an existing 2dsphere index (created while still using MongoDB 2.4.x):

              {
                      "v" : 1,
                      "key" : {
                              "l" : "2dsphere"
                      },
                      "ns" : "demo.foursquare",
                      "name" : "l_2dsphere"
              },
      

      I have some code that adds stuff from foursquare, and this script runs PHP's ensureIndex() to create the 2dsphere index in case it doesn't exist. On the shell, the equivalant is:

      db.foursquare.ensureIndex( { l: '2dsphere' } );
      

      However, that generates:

      {
              "ok" : 0,
              "errmsg" : "Index with name: l_2dsphere already exists with different options",
              "code" : 67
      }
      

      But I am not setting any new options.

      However, when I create a 2dsphere index on a different field (loc instead of l):

      db.foursquare.createIndex( { loc: '2dsphere' } );
      

      Then it creates this index:

              {
                      "v" : 1,
                      "key" : {
                              "loc" : "2dsphere"
                      },
                      "name" : "loc_2dsphere",
                      "ns" : "demo.foursquare",
                      "2dsphereIndexVersion" : 2
              }
      

      (Note the extra "2dsphereIndexVersion" : 2).

      When I then run the createIndex again, I get (correctly):

      { "numIndexesBefore" : 4, "note" : "all indexes already exist", "ok" : 1 }
      

      It looks like it breaks over the extra 2dsphereIndexVersion "option", but as user I have no influence over that not being set.

        1. server13875.js
          2 kB
          David Storch

            Assignee:
            rassi J Rassi
            Reporter:
            derick Derick Rethans
            Votes:
            0 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved: