[SERVER-12439] $where in $elemMatch no longer valid in 2.5.5-pre Created: 22/Jan/14  Updated: 11/Jul/16  Resolved: 04/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 2.6.0-rc0

Type: Bug Priority: Major - P3
Reporter: Andrew Emil (Inactive) Assignee: David Storch
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-14010 Use of $where within $elemMatch Closed
Related
related to SERVER-11731 $where inside of projection $elemMatc... Closed
related to SERVER-13503 The $where operator should not be all... Closed
is related to DOCS-3449 Doc that $where must be top-level Closed
Backwards Compatibility: Major Change
Operating System: ALL
Participants:

 Description   

A query that used to not error now will result in the error. From what I can see this is correct behavior, but it should be documented/noted.

On 2.4.9:

> db.myCollection.find( {x: {$elemMatch: { $where: "this.credits == this.debits" }}} );
>

On 2.5.5-pre

> db.runCommand({"buildinfo": 1})
{
        "version" : "2.5.5-pre-",
        "gitVersion" : "f65a0b814b8c77e3fbe90bca0c061c9b77f6acdb",
        "OpenSSLVersion" : "",
        "sysInfo" : "Darwin Andrew-Emil-MacBook-Pro.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May  1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49",
        "loaderFlags" : "-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.6",
        "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 -mmacosx-version-min=10.6",
        "allocator" : "tcmalloc",
        "versionArray" : [
                2,
                5,
                5,
                -100
        ],
        "javascriptEngine" : "V8",
        "bits" : 64,
        "debug" : false,
        "maxBsonObjectSize" : 16777216,
        "ok" : 1
}
> db.myCollection.find( {x: {$elemMatch: { $where: "this.credits == this.debits" }}} );
error: {
        "$err" : "Can't canonicalize query: BadValue unknown operator: $where",
        "code" : 17287
}



 Comments   
Comment by Githook User [ 04/Feb/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-12439 test that $where must be top level
Branch: master
https://github.com/mongodb/mongo/commit/d332c23dc7c29329322b8481ea477e42e476db11

Comment by Daniel Pasette (Inactive) [ 22/Jan/14 ]

i think this is works as designed and that it worked before was unintentional.

david.storch, can you close with a test?

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