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

2dsphere indexes with {2dsphereIndexVersion:2} should be sparse on geo fields

    Details

    • Backwards Compatibility:
      Major Change
    • Operating System:
      ALL

      Description

      Starting in 2.6.0-rc0, there are two versions of 2dsphere indexes. All new 2dsphere indexes starting in 2.6.0-rc0 are created with {2dsphereIndexVersion:2}. The V2 behavior is consistent with the behavior of 2d indexes with regards to 'sparseness'

      {2dsphereIndexVersion: 1} indexes:

      • Do not support new GeoJSON geometries introduced in 2.5.0: (MultiPoint, MultiLineString, MultiPolygon,
        GeometryCollection).
      • Are not sparse and do not recognize the {sparse: true}

        index modifier.

      • Documents which contain null or "empty" [] for the geo field are rejected and not inserted into the collection.
      • Documents with the geo field undefined are indexed and added to the collection.
      • It is possible to preserve the V1 behavior by indicating the version when creating the index. See SERVER-12175.
        For example, coll.ensureIndex( {geo: "2dsphere"}, {"2dsphereIndexVersion": 1});

      {2dsphereIndexVersion: 2} indexes:

      • Ignore the sparse flag and print a warning to the server log if it's set.
      • If a document lacks a 2dsphere-indexed field (or the field is null or an empty array) the document is inserted but not added to the index.

      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Original Ticket Description
      2dsphere indexes does not honor the sparse option. By contrast, 2d indexes are "sparse" by default and require all the fields from the index definition to be present in the document for the document to be included in the index.

      Don't know if this is an oversight or by design, but sparse functionality for 2dsphere is usable in the same way as sparse is usable for "normal" indexes.

        Issue Links

          Activity

          Hide
          pascal-bach Pascal Bach added a comment -

          Will this also work if the coordinates field is an empty array?
          Mongoose for example by default creates empty arrays, they should behave the same way as a null value I suggest.

          Show
          pascal-bach Pascal Bach added a comment - Will this also work if the coordinates field is an empty array? Mongoose for example by default creates empty arrays, they should behave the same way as a null value I suggest.
          Hide
          dan@10gen.com Dan Pasette added a comment -

          Pascal Bach, the behavior for 2.6 will be unchanged from the behavior in 2.4.

          Show
          dan@10gen.com Dan Pasette added a comment - Pascal Bach , the behavior for 2.6 will be unchanged from the behavior in 2.4.
          Hide
          pascal-bach Pascal Bach added a comment -

          I got that, I just wanted to make sure if this gets implemented in a later version it also works with empty arrays.

          On the other hand. Is there an alternative solution that allows indexing coordinates that are optional?

          For the moment I use legacy 2d indexes but I would really like to use the 2dspehre index.

          Show
          pascal-bach Pascal Bach added a comment - I got that, I just wanted to make sure if this gets implemented in a later version it also works with empty arrays. On the other hand. Is there an alternative solution that allows indexing coordinates that are optional? For the moment I use legacy 2d indexes but I would really like to use the 2dspehre index.
          Hide
          jhn Johan Hedin added a comment -

          Dan Pasette, is it possible to resolve this issue with the new 2dsphere index version tag?

          See: https://jira.mongodb.org/browse/SERVER-12175

          Show
          jhn Johan Hedin added a comment - Dan Pasette , is it possible to resolve this issue with the new 2dsphere index version tag? See: https://jira.mongodb.org/browse/SERVER-12175
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'hkhalsa', u'name': u'Hari Khalsa', u'email': u'hkhalsa@10gen.com'}

          Message: SERVER-9639 For 2dsphere V2 indices don't index any docs missing any geo fields

          This reverts commit 3b5b35c15690769df2a11a75a3c6e6afd7c2169a.
          Branch: master
          https://github.com/mongodb/mongo/commit/269c683220692299b5fb9cf431359e3ec299f8fc

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'hkhalsa', u'name': u'Hari Khalsa', u'email': u'hkhalsa@10gen.com'} Message: SERVER-9639 For 2dsphere V2 indices don't index any docs missing any geo fields This reverts commit 3b5b35c15690769df2a11a75a3c6e6afd7c2169a. Branch: master https://github.com/mongodb/mongo/commit/269c683220692299b5fb9cf431359e3ec299f8fc

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                1 year, 23 weeks, 2 days ago
                Date of 1st Reply: