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

Assertion error when using $elemMatch query with $ne operator and index

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Querying
    • None
    • ALL
    • Hide
      > db
      test
      > db.col.find({$and : [{'foo' : {$elemMatch : {$and : [{'bar' : {$ne : 'baz'}}]}}}, {'a.b' : {$elemMatch : {$and: [{'c' : 'd'}]}}}]})
      > db.col.ensureIndex({'foo.bar' : 1})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.col.find({$and : [{'foo' : {$elemMatch : {$and : [{'bar' : {$ne : 'baz'}}]}}}, {'a.b' : {$elemMatch : {$and: [{'c' : 'd'}]}}}]})
      error: { "$err" : "assertion src/mongo/db/query/planner_access.cpp:851" }
      > db.serverBuildInfo()
      {
      	"version" : "2.6.1",
      	"gitVersion" : "4b95b086d2374bdcfcdf2249272fb552c9c726e8",
      	"OpenSSLVersion" : "",
      	"sysInfo" : "Linux build14.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49",
      	"loaderFlags" : "-fPIC -pthread -Wl,-z,now -rdynamic",
      	"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -pipe -O3 -Wno-unused-function -Wno-deprecated-declarations -fno-builtin-memcmp",
      	"allocator" : "tcmalloc",
      	"versionArray" : [
      		2,
      		6,
      		1,
      		0
      	],
      	"javascriptEngine" : "V8",
      	"bits" : 64,
      	"debug" : false,
      	"maxBsonObjectSize" : 16777216,
      	"ok" : 1
      }
      > 
      
      Show
      > db test > db.col.find({$and : [{ 'foo' : {$elemMatch : {$and : [{ 'bar' : {$ne : 'baz' }}]}}}, { 'a.b' : {$elemMatch : {$and: [{ 'c' : 'd' }]}}}]}) > db.col.ensureIndex({ 'foo.bar' : 1}) { "createdCollectionAutomatically" : true , "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.col.find({$and : [{ 'foo' : {$elemMatch : {$and : [{ 'bar' : {$ne : 'baz' }}]}}}, { 'a.b' : {$elemMatch : {$and: [{ 'c' : 'd' }]}}}]}) error: { "$err" : "assertion src/mongo/db/query/planner_access.cpp:851" } > db.serverBuildInfo() { "version" : "2.6.1" , "gitVersion" : "4b95b086d2374bdcfcdf2249272fb552c9c726e8" , "OpenSSLVersion" : "", "sysInfo" : "Linux build14.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49" , "loaderFlags" : "-fPIC -pthread -Wl,-z,now -rdynamic" , "compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -pipe -O3 -Wno-unused-function -Wno-deprecated-declarations -fno-builtin-memcmp" , "allocator" : "tcmalloc" , "versionArray" : [ 2, 6, 1, 0 ], "javascriptEngine" : "V8" , "bits" : 64, "debug" : false , "maxBsonObjectSize" : 16777216, "ok" : 1 } >

      Query on nested arrays using $elemMatch executes correctly without indexes. Building an index on one or both of the nested array fields results in:

      failed: exception: assertion src/mongo/db/query/planner_access.cpp:851

      It seems to have something to do with the operator, as 'foo' : 'bar' works, but 'foo' : {$ne : 'bar'} doesn't.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            chash Curtis Hash
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: