[DOCS-12001] Documentation of $[<identifier>] contradicts documentation of update Created: 27/Aug/18  Updated: 30/Oct/23  Resolved: 15/Nov/18

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

Type: Improvement Priority: Minor - P4
Reporter: Dario Cutillas Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 5 years, 13 weeks ago
Epic Link: DOCSP-1769

 Description   

----------------------------

Original Description

In the documentation of the $[<identifier>] operator, section Update All Array Elements that Match Multiple Conditions, it states:

To modify the value of the std field for all elements in the grades array where both the grade is greater than or equal to 80 and the std is greater than or equal to 5, use the positional $[<identifier>] operator and arrayFilters:

db.students.update(
   { },
   { $inc: { "grades.$[elem].std" : -1 } },
   { arrayFilters: [ { "elem.grade": { $gte: 80 }, "elem.std": { $gt: 5 } } ], multi: true }
)

However, isn't that contradictory to what it is explained in the update operation documentation with regards to arrayFilter?:

You can include the same identifier multiple times in the update document; however, for each distinct identifier ($[identifier]) in the update document, you must specify exactly one corresponding array filter document. That is, you cannot specify multiple array filter documents for the same identifier. For example, if the update statement includes the identifier x (possibly multiple times), you cannot specify the following value for arrayFilters:

[ { "x.a": { $gt: 85} }, { "x.b": { $gt: 80 } } ]

----------------------------

Description

Scope of changes (files that need work and how much)

Impact to other docs outside of this product

MVP (work and date?)

Resources (e.g. Scope Docs, Invision)



 Comments   
Comment by Githook User [ 15/Nov/18 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@mongodb.com'}

Message: DOCS-12001: format restriction on arrayFilter for clarity
Branch: master
https://github.com/mongodb/docs/commit/d448c2833d0d0f979848e10a5aa0572b8398d908

Comment by Githook User [ 15/Nov/18 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@mongodb.com'}

Message: DOCS-12001: format restriction on arrayFilter for clarity
Branch: v3.6
https://github.com/mongodb/docs/commit/3bdd876767b70c090297b79092165d46d7cad755

Comment by Githook User [ 15/Nov/18 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@mongodb.com'}

Message: DOCS-12001: format restriction on arrayFilter for clarity
Branch: v4.0
https://github.com/mongodb/docs/commit/47405e28dbbe971c009adce07ba80dccebc9da6b

Comment by Kay Kim (Inactive) [ 15/Nov/18 ]

Thanks for filing this ticket. I think the formatting of the example in the update page may be the source of confusion:
In the update page, there are actually 2 array filter documents --( I've added page breaks here for readability)

[ 
  { "x.a": { $gt: 85} }, 
  { "x.b": { $gt: 80 } }
 ]

Whereas in the identifier page, there's only one filter document for "elem" that contains the two fields:

[ 
     { "elem.grade": { $gte: 80 },     "elem.std": { $gt: 5 } }
]

We will update the doc so that
1) It's easier to read the error case
2) Fix the bug in the example where the collection name should be students2 in that example.

Thanks again for taking the time to file the ticket. Much appreciated.

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