Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44422

Allow findAndModify and delete one to target by query instead of extracted shard key

    • Sharding NYC
    • Fully Compatible
    • v7.0, v6.0, v5.0
    • Sharding NYC 2023-06-26, Sharding NYC 2023-07-10, Sharding NYC 2023-07-24

      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 .

            wenqin.ye@mongodb.com Wenqin Ye
            jack.mulrow@mongodb.com Jack Mulrow
            1 Vote for this issue
            10 Start watching this issue