* ProcessUpdate processes a single update operation defined in * updateSpec on the given collection. */
| 1642 | * updateSpec on the given collection. |
| 1643 | */ |
| 1644 | static void |
| 1645 | ProcessUpdate(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 | */ |
no test coverage detected