* UpdateOne is the top-level function for updates with multi:false. It internally * calls ApiInternalSchemaName.update_one(..) to perform an update or delete of a single * row on a specific shard. If update_one returns a reinsert flag, which indicates * a change of shard_key_value, it additionally reinserts the document. */
| 2218 | * a change of shard_key_value, it additionally reinserts the document. |
| 2219 | */ |
| 2220 | void |
| 2221 | UpdateOne(MongoCollection *collection, UpdateOneParams *updateOneParams, |
| 2222 | int64 shardKeyHash, text *transactionId, UpdateOneResult *result, |
| 2223 | bool forceInlineWrites, ExprEvalState *stateForSchemaValidation) |
| 2224 | { |
| 2225 | CallUpdateOne(collection, updateOneParams, shardKeyHash, transactionId, result, |
| 2226 | forceInlineWrites, stateForSchemaValidation); |
| 2227 | |
| 2228 | /* check for shard key value changes */ |
| 2229 | if (result->reinsertDocument) |
| 2230 | { |
| 2231 | /* compute new shard key hash */ |
| 2232 | int64 newShardKeyHash = |
| 2233 | ComputeShardKeyHashForDocument(collection->shardKey, collection->collectionId, |
| 2234 | result->reinsertDocument); |
| 2235 | |
| 2236 | /* extract object ID */ |
| 2237 | pgbson *objectId = PgbsonGetDocumentId(result->reinsertDocument); |
| 2238 | |
| 2239 | /* If we have to reinsert the document in a different shard */ |
| 2240 | bool queryHasNonIdFilters = false; |
| 2241 | bool isIdFilterCollationAwareIgnore = false; |
| 2242 | pgbson *objectIdFilter = GetObjectIdFilterFromQueryDocumentValue( |
| 2243 | updateOneParams->query, &queryHasNonIdFilters, |
| 2244 | &isIdFilterCollationAwareIgnore); |
| 2245 | bool hasOnlyObjectIdFilter = objectIdFilter != NULL && !queryHasNonIdFilters; |
| 2246 | |
| 2247 | DoInsertForUpdate(collection, newShardKeyHash, objectId, result->reinsertDocument, |
| 2248 | hasOnlyObjectIdFilter, updateOneParams->update); |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | static void |
no test coverage detected