Serializes the update one params and shardkey bson as a pgbson to send down to the worker. */
| 2725 | |
| 2726 | /* Serializes the update one params and shardkey bson as a pgbson to send down to the worker. */ |
| 2727 | static pgbson * |
| 2728 | SerializeUpdateOneParams(UpdateOneParams *params, pgbson *shardKeyBson) |
| 2729 | { |
| 2730 | pgbson_writer commandWriter; |
| 2731 | PgbsonWriterInit(&commandWriter); |
| 2732 | |
| 2733 | pgbson_writer writer; |
| 2734 | PgbsonWriterStartDocument(&commandWriter, "updateOne", -1, &writer); |
| 2735 | |
| 2736 | if (params->query != NULL) |
| 2737 | { |
| 2738 | PgbsonWriterAppendValue(&writer, "query", -1, params->query); |
| 2739 | } |
| 2740 | |
| 2741 | if (shardKeyBson != NULL) |
| 2742 | { |
| 2743 | PgbsonWriterAppendDocument(&writer, "shardKeyBson", -1, shardKeyBson); |
| 2744 | } |
| 2745 | |
| 2746 | /* Back-compat (to handle new coordinator, old worker) |
| 2747 | * write it as a document that is { "": value } |
| 2748 | * TODO: See if this can be elided in the future |
| 2749 | */ |
| 2750 | pgbson_writer valueWriter; |
| 2751 | PgbsonWriterStartDocument(&writer, "update", -1, &valueWriter); |
| 2752 | PgbsonWriterAppendValue(&valueWriter, "", 0, params->update); |
| 2753 | PgbsonWriterEndDocument(&writer, &valueWriter); |
| 2754 | |
| 2755 | PgbsonWriterAppendBool(&writer, "isUpsert", -1, params->isUpsert != 0); |
| 2756 | |
| 2757 | PgbsonWriterAppendBool(&writer, "bypassDocumentValidation", -1, |
| 2758 | params->bypassDocumentValidation); |
| 2759 | |
| 2760 | if (params->sort != NULL) |
| 2761 | { |
| 2762 | PgbsonWriterAppendValue(&writer, "sort", 4, params->sort); |
| 2763 | } |
| 2764 | |
| 2765 | PgbsonWriterAppendInt32(&writer, "returnDocument", -1, (int) params->returnDocument); |
| 2766 | |
| 2767 | if (params->returnFields != NULL) |
| 2768 | { |
| 2769 | PgbsonWriterAppendValue(&writer, "returnFields", -1, params->returnFields); |
| 2770 | } |
| 2771 | |
| 2772 | if (params->arrayFilters != NULL) |
| 2773 | { |
| 2774 | /* |
| 2775 | * back compat: To handle new coordinator old worker scenario, write it in the |
| 2776 | * prior format of { "": value } |
| 2777 | * TODO: See if this can be elided in the future |
| 2778 | */ |
| 2779 | PgbsonWriterStartDocument(&writer, "arrayFilters", -1, &valueWriter); |
| 2780 | PgbsonWriterAppendValue(&valueWriter, "", 0, params->arrayFilters); |
| 2781 | PgbsonWriterEndDocument(&writer, &valueWriter); |
| 2782 | } |
| 2783 | |
| 2784 | if (params->variableSpec != NULL && |
no test coverage detected