[SERVER-13897] Assertion error when using $elemMatch query with $ne operator and index Created: 09/May/14  Updated: 10/Dec/14  Resolved: 10/May/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Curtis Hash Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-13789 Some nested queries trigger an assert... Closed
Operating System: ALL
Steps To Reproduce:

> 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
}
> 

Participants:

 Description   

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.



 Comments   
Comment by David Storch [ 10/May/14 ]

Confirmed as a known issue that has already been fixed as part of SERVER-13789. The fix is currently scheduled for release in version 2.6.2. chash, thanks very much for the bug report with detailed repro steps!

Comment by J Rassi [ 09/May/14 ]

I believe this is a dup of SERVER-13789. david.storch, can you confirm that the patch for 13789 fixes this query as well?

Generated at Thu Feb 08 03:33:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.