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

$geoWithin queries have missing results when location field has extra sub-fields

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Query Integration
    • ALL
    • Hide

      // Insert identical documents with different field orders

      replset [direct: primary] test> db.test.find()
      [
      {
      _id: ObjectId("65a04bdf95d67a5d1230b4c3"),
      be:

      { ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point' }

      },
      {
      _id: ObjectId("65a04c0895d67a5d1230b4c4"),
      be:

      { coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point', ua: 209268.984375 }

      },
      {
      _id: ObjectId("65a04fae95d67a5d1230b4c5"),
      be:

      { coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375, type: 'Point' }

      },
      {
      _id: ObjectId("65a04fd395d67a5d1230b4c6"),
      be:

      { type: 'Point', ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ] }

      },
      {
      _id: ObjectId("65a0506095d67a5d1230b4c7"),
      be:

      { ua: 209268.984375, type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ] }

      },
      {
      _id: ObjectId("65a050ae95d67a5d1230b4c8"),
      be:

      { type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375 }

      }
      ]
       
      // $geoWithin query only matches documents that don't have the numeric field as the first field

      replset [direct: primary] test> db.test.find({ $or: [{ "be": { $geoWithin:

      { $centerSphere: [[179.03531532305314, 0.7050703681776871], 2.145221550434281] }

      } }] })
      [
      {
      _id: ObjectId("65a04c0895d67a5d1230b4c4"),
      be:

      { coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point', ua: 209268.984375 }

      },
      {
      _id: ObjectId("65a04fae95d67a5d1230b4c5"),
      be:

      { coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375, type: 'Point' }

      },
      {
      _id: ObjectId("65a04fd395d67a5d1230b4c6"),
      be:

      { type: 'Point', ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ] }

      },
      {
      _id: ObjectId("65a050ae95d67a5d1230b4c8"),
      be:

      { type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375 }

      }
      ]

      Show
      // Insert identical documents with different field orders replset [direct: primary] test> db.test.find() [ { _id: ObjectId("65a04bdf95d67a5d1230b4c3"), be: { ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point' } }, { _id: ObjectId("65a04c0895d67a5d1230b4c4"), be: { coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point', ua: 209268.984375 } }, { _id: ObjectId("65a04fae95d67a5d1230b4c5"), be: { coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375, type: 'Point' } }, { _id: ObjectId("65a04fd395d67a5d1230b4c6"), be: { type: 'Point', ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ] } }, { _id: ObjectId("65a0506095d67a5d1230b4c7"), be: { ua: 209268.984375, type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ] } }, { _id: ObjectId("65a050ae95d67a5d1230b4c8"), be: { type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375 } } ]   // $geoWithin query only matches documents that don't have the numeric field as the first field replset [direct: primary] test> db.test.find({ $or: [{ "be": { $geoWithin: { $centerSphere: [[179.03531532305314, 0.7050703681776871], 2.145221550434281] } } }] }) [ { _id: ObjectId("65a04c0895d67a5d1230b4c4"), be: { coordinates: [ -95.90898701416783, -78.02003547216432 ], type: 'Point', ua: 209268.984375 } }, { _id: ObjectId("65a04fae95d67a5d1230b4c5"), be: { coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375, type: 'Point' } }, { _id: ObjectId("65a04fd395d67a5d1230b4c6"), be: { type: 'Point', ua: 209268.984375, coordinates: [ -95.90898701416783, -78.02003547216432 ] } }, { _id: ObjectId("65a050ae95d67a5d1230b4c8"), be: { type: 'Point', coordinates: [ -95.90898701416783, -78.02003547216432 ], ua: 209268.984375 } } ]

      When working with GeoJSON data, we expect location fields to be one sub-object with a "type" and "coordinates" field. When there's an extra field in the field's sub-object, some $geoWithin queries miss matching documents.

      See reproducing steps for more details.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            will.buerger@mongodb.com Will Buerger
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: