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

Function ProcessUpdate

pg_documentdb/src/commands/update.c:1644–1789  ·  view source on GitHub ↗

* ProcessUpdate processes a single update operation defined in * updateSpec on the given collection. */

Source from the content-addressed store, hash-verified

1642 * updateSpec on the given collection.
1643 */
1644static void
1645ProcessUpdate(MongoCollection *collection, UpdateSpec *updateSpec,
1646 text *transactionId, UpdateResult *result, bool forceInlineWrites,
1647 ExprEvalState *stateForSchemaValidation)
1648{
1649 const bson_value_t *query = updateSpec->updateOneParams.query;
1650 const bson_value_t *update = updateSpec->updateOneParams.update;
1651 const bson_value_t *arrayFilters = updateSpec->updateOneParams.arrayFilters;
1652 bool isUpsert = updateSpec->updateOneParams.isUpsert;
1653 bool isMulti = updateSpec->isMulti;
1654
1655 /* sort cannot be performed when multi is set to true */
1656 if (isMulti && updateSpec->updateOneParams.sort != NULL)
1657 {
1658 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE),
1659 errmsg("sort option can not be set when multi=true")));
1660 }
1661
1662 /* determine whether query filters by a single shard key value */
1663 int64 shardKeyHash = 0;
1664 bool isShardKeyValueCollationAware = false;
1665 bool hasShardKeyValueFilter =
1666 ComputeShardKeyHashForQueryValue(collection->shardKey, collection->collectionId,
1667 query,
1668 &shardKeyHash, &isShardKeyValueCollationAware);
1669
1670 result->rowsMatched = 0;
1671 result->rowsModified = 0;
1672 result->performedUpsert = false;
1673 result->upsertedObjectId = NULL;
1674
1675 if (isMulti)
1676 {
1677 if (DetermineUpdateType(update) == UpdateType_ReplaceDocument)
1678 {
1679 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE),
1680 errmsg(
1681 "multi=true and replace-style updates cannot be used together.")));
1682 }
1683
1684
1685 /*
1686 * Update as many document as match the query. This is not a retryable
1687 * operation, so we ignore transactionId.
1688 */
1689 bool hasOnlyObjectIdFilter = false;
1690
1691 UpdateAllMatchingDocsResult updateAllResult = UpdateAllMatchingDocuments(
1692 collection, &updateSpec->updateOneParams,
1693 hasShardKeyValueFilter,
1694 shardKeyHash, stateForSchemaValidation,
1695 &hasOnlyObjectIdFilter);
1696 result->rowsMatched = updateAllResult.matchedDocs;
1697 result->rowsModified = updateAllResult.rowsUpdated;
1698
1699 /*
1700 * In case of an upsert,
1701 */

Callers 3

DoMultiUpdateFunction · 0.85
DoSingleUpdateWithSubTxnFunction · 0.85
DoSingleUpdateFunction · 0.85

Calls 8

DetermineUpdateTypeFunction · 0.85
UpsertDocumentFunction · 0.85
UpdateOneFunction · 0.85
BsonValueInitIteratorFunction · 0.85
UpdateOneObjectIdFunction · 0.85

Tested by

no test coverage detected