[DOCS-14134] Positional projection operator fails if no query is specified for field Created: 05/Jan/21  Updated: 30/Oct/23  Due: 26/Feb/21  Resolved: 02/Mar/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Nikita Lapkov (Inactive) Assignee: Andrew Feierabend (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 2 years, 49 weeks, 1 day ago
Epic Link: DOCSP-11701
Story Points: 2

 Description   

Our documentation says that positional projection operator returns The first element if no query condition is specified for the array (Starting in MongoDB 4.4).

It looks like we do not have such behaviour implemented:

$ mongod --version
db version v4.4.1
Build Info: {
    "version": "4.4.1",
    "gitVersion": "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
 
> db.test.find()
{ "_id" : ObjectId("5ff47546d0e2d9910975e0cb"), "x" : 1, "a" : [ 1, 2, 3 ] }
 
> db.test.find({}, {'a.$': 1})
Error: error: {
	"ok" : 0,
	"errmsg" : "positional operator '.$' couldn't find a matching element in the array",
	"code" : 51246,
	"codeName" : "Location51246"
}
 
> db.test.find({x: 1}, {'a.$': 1})
Error: error: {
	"ok" : 0,
	"errmsg" : "positional operator '.$' couldn't find a matching element in the array",
	"code" : 51246,
	"codeName" : "Location51246"
}

In queries above we do not specify query condition for the array. The query fails instead of returning the first element of array in field a.



 Comments   
Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Andrew Feierabend', 'email': 'andrew.feierabend@mongodb.com', 'username': 'andf-mongodb'}

Message: DOCS-14134 fix positional projection array behavior
Branch: v3.6
https://github.com/mongodb/docs/commit/91b9b9bc0efdd6a69934ffc93b54632bafcc52f6

Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Andrew Feierabend', 'email': 'andrew.feierabend@mongodb.com', 'username': 'andf-mongodb'}

Message: DOCS-14134 fix positional projection array behavior
Branch: v4.0
https://github.com/mongodb/docs/commit/20db301fae35edfbe6dd134596aa4d269c11be39

Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Andrew Feierabend', 'email': 'andrew.feierabend@mongodb.com', 'username': 'andf-mongodb'}

Message: DOCS-14134 fix positional projection array behavior
Branch: v4.2
https://github.com/mongodb/docs/commit/e08423edaee9e2670df730708a288dab0e309120

Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Andrew Feierabend', 'email': 'andrew.feierabend@mongodb.com', 'username': 'andf-mongodb'}

Message: DOCS-14134 fix positional projection array behavior
Branch: master
https://github.com/mongodb/docs/commit/308855def42502ad7d6fdf764ab4bf57923aa32d

Comment by Githook User [ 02/Mar/21 ]

Author:

{'name': 'Andrew Feierabend', 'email': 'andrew.feierabend@mongodb.com', 'username': 'andf-mongodb'}

Message: DOCS-14134 fix positional projection array behavior
Branch: v5.0
https://github.com/mongodb/docs/commit/d4db4226f99c2b221525c0713cea43b37b3081bb

Comment by Asya Kamsky [ 12/Feb/21 ]

Flagging for re-triage to remove incorrect statement about 4.4 (see PR)

Comment by Asya Kamsky [ 19/Jan/21 ]

See https://github.com/mongodb/docs/pull/4750 for fix. The note about first element being picked starting in 4.4 is incorrect.

Comment by Ana Meza [ 05/Jan/21 ]

This is a Documentation problemĀ 

Comment by Asya Kamsky [ 05/Jan/21 ]

DOCS-13323 added this note which is incorrect. Will file remove the note.

Generated at Thu Feb 08 08:09:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.