Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16308

Investigate changes in SERVER-44422: Allow findAndModify and delete one to target by query instead of extracted shard key

      Original Downstream Change Summary

      Documentation for 6.0 and 5.0 will need to be updated to no longer say that you need an equality on the full shard key to perform findAndModify or deleteOne. You can now perform a findAndModify and deleteOne with a partial shard key in the query as long as only one shard is targeted.

      For example: if the shard key was {a: 1, b: 1}. Then previously a query such as findAndModify({a: 3}, {$set: {c: 10}}) would fail because the full shard key was not in the query. With the changes made in SERVER-44422 the findAndModify no longer fails as long as only one shard is targeted.

      Description of Linked Ticket

      findAndModify and delete with justOne=true must be targeted to a single shard which they check by extracting a shard key from their query and targeting the chunk that owns that key. This is done through ShardKeyPattern::extractShardKeyFromQuery() which requires a simple query that will exactly match some value, e.g. {skey: 5} or {skey; {$eq: 5}}. More complex queries that don't produce an exact match, but can still be targeted to a single shard are currently rejected.

      This could be improved by changing findAndModify and delete to target using ChunkManager::getShardIdsForQuery(), which returns the shards that own ranges that overlap with the shard key index bounds generated by the query (after checking for an exact shard key match first), and throwing if more than one shard is targeted. This is already how an update is targeted by its query .

            Assignee:
            jocelyn.mendez@mongodb.com Jocelyn Mendez
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              37 weeks, 4 days ago