[SERVER-40687] Positional projection ($) only considers first path component when comparing to query document Created: 17/Apr/19  Updated: 29/Oct/23  Resolved: 07/Dec/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.0.9
Fix Version/s: 4.3.3

Type: Bug Priority: Major - P3
Reporter: Piyush Kumar Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File bug1.png     PNG File mongo1.png     PNG File sub2.png    
Issue Links:
Depends
Documented
is documented by DOCS-13323 Investigate changes in SERVER-40687: ... Closed
Problem/Incident
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Query 2019-12-02, Query 2019-12-16
Participants:
Linked BF Score: 0

 Description   

Using a non-matching subfield (e.g., query: fieldExists.something: 1 projection: fieldExists.fieldDoesntExist.$) with the $ projection operator does not return the Positional projection 'fieldExists.fieldDoesntExist.$' does not match the query document error.
 
Given the document:

{
	"_id" : ObjectId("5cb8ab2f20926051ca9e2cd7"),
	"AOE" : [
		{
			"areaOfExpertise" : "aoe1",
			"subAOE" : []
		},
		{
			"areaOfExpertise" : "aoe2",
			"subAOE" : []
		}
	],
	"poolName" : "newpool",
	"__v" : 0
}

The {"AOE.doesntExist.$":1} projection is treated the same as the correct {"AOE.$":1} projection:

> db.proj.find({ poolName: "newpool", "AOE.areaOfExpertise": "aoe1" },{"AOE.doesntExist.$":1}).pretty()
{
	"_id" : ObjectId("5cb8ab2f20926051ca9e2cd7"),
	"AOE" : [
		{
			"areaOfExpertise" : "aoe1",
			"subAOE" : []
		}
	]
}
> db.proj.find({ poolName: "newpool", "AOE.areaOfExpertise": "aoe1" },{"AOE.$":1}).pretty()
{
	"_id" : ObjectId("5cb8ab2f20926051ca9e2cd7"),
	"AOE" : [
		{
			"areaOfExpertise" : "aoe1",
			"subAOE" : []
		}
	]
}



 Comments   
Comment by Ian Boros [ 06/Jan/20 ]

asya That's correct.

Comment by Githook User [ 06/Dec/19 ]

Author:

{'name': 'Ian Boros', 'username': 'puppyofkosh', 'email': 'ian.boros@mongodb.com'}

Message: SERVER-40687 remove unused variable
Branch: master
https://github.com/mongodb/mongo/commit/72788deb99186ac2628604505147e68ac53cffc5

Comment by Githook User [ 06/Dec/19 ]

Author:

{'name': 'Ian Boros', 'username': 'puppyofkosh', 'email': 'ian.boros@mongodb.com'}

Message: SERVER-40687 stricter checking on positional operator field
Branch: master
https://github.com/mongodb/mongo/commit/3bfcdd40ebcfa9786947213e47bf148655bab666

Comment by Ian Boros [ 03/Dec/19 ]

Ping asya

Comment by Piyush Kumar [ 18/Apr/19 ]

Thank you Eric for making this issue well documented.

Comment by Eric Sedor [ 18/Apr/19 ]

Thank you piyushkumar96; We understand what you are saying and are looking into this. I've also transferred your clarification into the original description of the ticket.

Comment by Piyush Kumar [ 18/Apr/19 ]

Hi Eric,
the content of document is below. As u can see the in "AOE" which an array of json. In JSON there is no such key GHGHGHGH.GHGHGHGHGHGH. There are only two keys "areaOfExpertise" and "subAOE" in "AOE" .

{
 "_id" : ObjectId("5cb7043715a7196aff239ee2"),
 "AOE" : [ 
 {
 "areaOfExpertise" : "aoe1",
 "subAOE" : [ 
 "s1", 
 "s2", 
 "s3", 
 "s4"
 ]
 }, 
 {
 "areaOfExpertise" : "aoe2",
 "subAOE" : [ 
 "s11", 
 "s12", 
 "s13", 
 "s14"
 ]
 }
 ],
 "poolName" : "newpool",
 "__v" : 0
}

correct query:--- findOne({
                poolName: "newpool",
                "AOE.areaOfExpertise": "aoe1"
            }, {_id: 0, 'AOE.$': 1})

if I am using the query (wrong query) which is mentioned below, its still giving the output not throwing the error.

wrong query:---   findOne({
                poolName: "newpool",
                "AOE.areaOfExpertise": "aoe1"
            }, {_id: 0, 'AOE.GHGHGHGH.GHGHGHGHGHGH.$.subAOE': 1})
 

Comment by Eric Sedor [ 17/Apr/19 ]

Would you be able to provide the contents of the document without a projection, to help us understand what you are expecting?

Generated at Thu Feb 08 04:55:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.