MCPcopy Create free account
hub / github.com/documentdb/documentdb / UpdateOne

Function UpdateOne

pg_documentdb/src/commands/update.c:2220–2250  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

2218 * a change of shard_key_value, it additionally reinserts the document.
2219 */
2220void
2221UpdateOne(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
2253static void

Callers 2

ProcessFindAndModifySpecFunction · 0.85
ProcessUpdateFunction · 0.85

Calls 5

CallUpdateOneFunction · 0.85
PgbsonGetDocumentIdFunction · 0.85
DoInsertForUpdateFunction · 0.85

Tested by

no test coverage detected