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

Distinct command on indexed field with geo predicate fails to execute

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.2, 2.7.0
    • Affects Version/s: 2.6.0
    • Component/s: Querying
    • Labels:
      None
    • ALL

      Issue Status as of June 6, 2014

      ISSUE SUMMARY
      The distinct command when run on an indexed field fails when the query portion of the command is on a field with a geo index (2d, 2dsphere).

      Example:

      db.foo.ensureIndex({a:1})
      db.foo.ensureIndex({"loc":"2d"})
      db.foo.distinct("a", {loc: {$nearSphere: [0,0]}})
      

      This will trigger the bug because a is indexed and the query on loc uses the geo index.

      USER IMPACT
      The distinct command fails. A a stack trace is included in the log file.

      WORKAROUNDS
      A workaround is to use the aggregation framework for the distinct calculation. For above example on a 2d index, the equivalent aggregation call would be:

      db.foo.aggregate( { $geoNear: { near: [0, 0], distanceField: "dist" } }, 
                        { $group: {_id: "$a" } } )
      { "_id" : 1 }
      { "_id" : 4 }
      { "_id" : 2 }
      { "_id" : 5 }
      { "_id" : 3 }
      

      Note that the aggregation call returns a cursor and the format differs slightly from the distinct format.

      AFFECTED VERSIONS
      Versions 2.6.0 and 2.6.1 are affected by this issue.

      FIX VERSION
      The fix is included in the 2.6.2 production release.

      RESOLUTION DETAILS
      The query planner now clears the index tags in the case of geo indexes.

      Original description

      In a collection that has the following _id:

      _id: {id: 'xxxx', d: MongoDate(xxx)}
      

      Calling a distinct query with the key of "_id.id" causes a failure in mongo as seen below.

      This error occurs in 2.6.0 and 2.6.1rc0. Mongodb 2.4.9 or earlier, does not have this error.

      If I copy the _id.id to just a "id" then run distinct on "id" the query runs properly.

      query:

      db.dailyArchive201404->distinct("_id.id", { ... });
      

      Error:

      2014-04-27T18:46:23.438+0000 [conn18] dailyArchive201404 0x11c1421 0x1163699 0x11474de 0xd7c6e6 0xd7c3d3 0xd837f8 0xd1b7c6 0xd1d832 0xd1f7e6 0xd20873 0x9344b5 0xa1e92a 0xa1f89e 0xa21156 0xd4dbb7 0xb973f2 0xb999d2 0x76b77f 0x117779b 0x7ffae5eedf18 
       /opt/mongodb/current/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0x11c1421]
       /opt/mongodb/current/bin/mongod(_ZN5mongo10logContextEPKc+0x159) [0x1163699]
       /opt/mongodb/current/bin/mongod(_ZN5mongo12verifyFailedEPKcS1_j+0x17e) [0x11474de]
       /opt/mongodb/current/bin/mongod(_ZN5mongo20QueryPlannerIXSelect11rateIndicesEPNS_15MatchExpressionESsRKSt6vectorINS_10IndexEntryESaIS4_EE+0x916) [0xd7c6e6]
       /opt/mongodb/current/bin/mongod(_ZN5mongo20QueryPlannerIXSelect11rateIndicesEPNS_15MatchExpressionESsRKSt6vectorINS_10IndexEntryESaIS4_EE+0x603) [0xd7c3d3]
       /opt/mongodb/current/bin/mongod(_ZN5mongo12QueryPlanner4planERKNS_14CanonicalQueryERKNS_18QueryPlannerParamsEPSt6vectorIPNS_13QuerySolutionESaIS9_EE+0x1c38) [0xd837f8]
       /opt/mongodb/current/bin/mongod(_ZN5mongo19getRunnerAlwaysPlanEPNS_10CollectionEPNS_14CanonicalQueryERKNS_18QueryPlannerParamsEPPNS_6RunnerE+0x86) [0xd1b7c6]
       /opt/mongodb/current/bin/mongod(_ZN5mongo9getRunnerEPNS_10CollectionEPNS_14CanonicalQueryEPPNS_6RunnerEm+0x932) [0xd1d832]
       /opt/mongodb/current/bin/mongod(_ZN5mongo9getRunnerEPNS_14CanonicalQueryEPPNS_6RunnerEm+0x96) [0xd1f7e6]
       /opt/mongodb/current/bin/mongod(_ZN5mongo17getRunnerDistinctEPNS_10CollectionERKNS_7BSONObjERKSsPPNS_6RunnerE+0x1003) [0xd20873]
       /opt/mongodb/current/bin/mongod(_ZN5mongo15DistinctCommand3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb+0x915) [0x9344b5]
       /opt/mongodb/current/bin/mongod(_ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb+0x3a) [0xa1e92a]
       /opt/mongodb/current/bin/mongod(_ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb+0xc5e) [0xa1f89e]
       /opt/mongodb/current/bin/mongod(_ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi+0x6c6) [0xa21156]
       /opt/mongodb/current/bin/mongod(_ZN5mongo11newRunQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_+0x2307) [0xd4dbb7]
       /opt/mongodb/current/bin/mongod() [0xb973f2]
       /opt/mongodb/current/bin/mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0x442) [0xb999d2]
       /opt/mongodb/current/bin/mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0x9f) [0x76b77f]
       /opt/mongodb/current/bin/mongod(_ZN5mongo17PortMessageServer17handleIncomingMsgEPv+0x4fb) [0x117779b]
       /lib64/libpthread.so.0(+0x7f18) [0x7ffae5eedf18]
      

            Assignee:
            rassi J Rassi
            Reporter:
            hwleeh Lee Huffman
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: