* Given a query spec, walks the query and builds a document that * will be used in the upsert case as the initial document. */
| 849 | * will be used in the upsert case as the initial document. |
| 850 | */ |
| 851 | static pgbson * |
| 852 | BuildBsonDocumentFromQuery(pgbson *sourceDoc, const bson_value_t *querySpec, |
| 853 | UpdateType updateType) |
| 854 | { |
| 855 | BsonIntermediatePathNode *root = MakeRootNode(); |
| 856 | |
| 857 | bson_iter_t queryDocIterator; |
| 858 | BsonValueInitIterator(querySpec, &queryDocIterator); |
| 859 | QueryProjectionContext context = { .root = root, .updateType = updateType }; |
| 860 | |
| 861 | bool isUpsert = true; |
| 862 | const ProcessQueryFilterFunc processFilterFunc = NULL; |
| 863 | TraverseQueryDocumentAndProcess(&queryDocIterator, &context, |
| 864 | &ProcessQueryProjectionValue, |
| 865 | processFilterFunc, |
| 866 | isUpsert); |
| 867 | pgbson_writer writer; |
| 868 | PgbsonWriterInit(&writer); |
| 869 | |
| 870 | bson_iter_t sourceDocIterator; |
| 871 | PgbsonInitIterator(sourceDoc, &sourceDocIterator); |
| 872 | bool projectNonMatchingFields = true; |
| 873 | ProjectDocumentState projectDocState = { |
| 874 | .isPositionalAlreadyEvaluated = false, |
| 875 | .parentDocument = sourceDoc, |
| 876 | .topLevelPendingProjectionState = NULL, |
| 877 | .skipIntermediateArrayFields = false, |
| 878 | }; |
| 879 | |
| 880 | bool isInNestedArray = false; |
| 881 | TraverseObjectAndAppendToWriter(&sourceDocIterator, root, &writer, |
| 882 | projectNonMatchingFields, |
| 883 | &projectDocState, isInNestedArray); |
| 884 | return PgbsonWriterGetPgbson(&writer); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | /* |
no test coverage detected