[SERVER-35220] Updating a document with dotted notation failed with PathNotViable if array is sufficiently large Created: 25/May/18  Updated: 26/Jun/20  Resolved: 08/Jun/18

Status: Closed
Project: Core Server
Component/s: Querying, Write Ops
Affects Version/s: 3.6.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kevin Adistambha Assignee: Charlie Swanson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File PathNotViable.js    
Issue Links:
Duplicate
duplicates SERVER-33687 Sort order of array indexes can deter... Closed
Related
Operating System: ALL
Sprint: Query 2018-06-18
Participants:

 Description   
  1. Attempting to update an array using dotted notation failed with a PathNotViable error (code 28) if the array is sufficiently large.

Attached is a jstest that creates an empty array, then attempts to insert 10 new elements into the array using dotted notation such as {$set: {"array.0.content": "x"}}: PathNotViable.js

 The test will fail if we attempt to insert 10 elements at once. It will succeed when we try to insert fewer than that, e.g. 9 elements.

The error message printed in the console is as follows:

Cannot create field 'content' in element {: null}
WriteResult({
  "nMatched": 0,
  "nUpserted": 0,
  "nModified": 0,
  "writeError": {
    "code": 28,
    "errmsg": "Cannot create field 'content' in element {: null}"
  }
})

 This also happens when inserting the same number of elements using Pymongo.



 Comments   
Comment by Charlie Swanson [ 08/Jun/18 ]

Hi kevin.adistambha,

It looks like you're running into SERVER-33687, so I've closed this ticket as a duplicate. Have you considered using any of the new syntax introduced with arrayFilters?

In your example, supposing you actually want to update all of the elements in the array, I think you could do so via

db.test.update(
  {_id: 0},
  {$set: {"array.$[].content": "x"}}
)

If you want to go from an empty array to an array with 10 elements, could you just manually create the array yourself? Something like

db.test.update(
  {_id: 0},
  {$set: {array: [{content: "x"}, {content: "x"}, ...]}}
)

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