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

Issue when using spatial query within filter using $and

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.1.0
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      Windows 7 32 bit
    • ALL

      I am getting errors when I try a spatial query within an "$and" operator.

      I can run the following queries successfully:

      db.LOGGER.find({ "COORDINATES" : { "$within" :

      { "$polygon" : [[22000, 60000], [22000, 63000], [23000, 63000], [23000, 60000]] }

      } });
      db.LOGGER.find({ "$and" : [{ "TIME" :

      { "$gte" : NumberLong("3542546522557") }

      }, { "TIME" :

      { "$lt" : NumberLong("3542546575557") }

      }] });

      However when I add the spatial query to the "$and" I get the following error:

      db.LOGGER.find({ "$and" : [{ "COORDINATES" : { "$within" :

      { "$polygon" : [[22000, 60000], [22000, 63000], [23000, 63000], [23000, 60000]] }

      } },{ "TIME" :

      { "$gte" : NumberLong("3542546522557") }

      }, { "TIME" :

      { "$lt" : NumberLong("3542546575557") }

      }] });

      error: {
      "$err" : "can't find special index: 2d for: { $and: [ { COORDINATES: { $within:

      { $polygon: [ [ 22000.0, 60000.0 ], [ 22000.0, 63000.0 ], [ 23000.0, 63000.0 ], [ 23000.0, 60000.0 ] ] }

      } }, { TIME:

      { $gte: 3542546522557 }

      }, { TIME:

      { $lt: 3542546575557 }

      } ] }",
      "code" : 13038
      }

      I have a collection with the following format:
      {
      "_id" : ObjectId("4f7c7a07d2fdb8c2db481a24"),
      "ID_NAME" : NumberLong(0),
      "SYSTEM_REFERENCE" : "0",
      "TIME" : NumberLong("3542546568559"),
      "COORDINATES" :

      { "X_COORD" : NumberLong(22682), "Y_COORD" : NumberLong(62220), "Z_COORD" : NumberLong(13) }

      }
      There is a 2d spatial index on "COORDINATES"
      Indexes are:

      db.LOGGER.getIndexes()
      [
      {
      "name" : "id",
      "ns" : "TEST.LOGGER",
      "key" :

      { "_id" : 1 }

      ,
      "v" : 0
      },
      {
      "_id" : ObjectId("4f7c7b5aa22c3db066674ba0"),
      "ns" : "TEST.LOGGER",
      "key" :

      { "COORDINATES" : "2d" }

      ,
      "name" : "Coord",
      "min" : 0,
      "max" : 101000
      }
      ]

            Assignee:
            siddharth.singh@10gen.com siddharth.singh@10gen.com
            Reporter:
            schaffer M Schaffer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: