* BuildUpdateSpec builds a UpdateSpec from the BSON of a single update * operation. */
| 968 | * operation. |
| 969 | */ |
| 970 | static UpdateSpec * |
| 971 | BuildUpdateSpec(bson_iter_t *updateIter, const bson_value_t *variableSpec) |
| 972 | { |
| 973 | bson_value_t *query = NULL; |
| 974 | bson_value_t *update = NULL; |
| 975 | bson_value_t *arrayFilters = NULL; |
| 976 | bool isMulti = false; |
| 977 | bool isUpsert = false; |
| 978 | bson_value_t *sort = NULL; |
| 979 | |
| 980 | while (bson_iter_next(updateIter)) |
| 981 | { |
| 982 | const char *field = bson_iter_key(updateIter); |
| 983 | |
| 984 | if (strcmp(field, "q") == 0) |
| 985 | { |
| 986 | EnsureTopLevelFieldType("update.updates.q", updateIter, BSON_TYPE_DOCUMENT); |
| 987 | |
| 988 | query = palloc(sizeof(bson_value_t)); |
| 989 | *query = *bson_iter_value(updateIter); |
| 990 | } |
| 991 | else if (strcmp(field, "u") == 0) |
| 992 | { |
| 993 | if (!BSON_ITER_HOLDS_DOCUMENT(updateIter) && |
| 994 | !BSON_ITER_HOLDS_ARRAY(updateIter)) |
| 995 | { |
| 996 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), |
| 997 | errmsg("BSON field 'update.updates.u' is the wrong type " |
| 998 | "'%s', expected type 'object' or 'array'", |
| 999 | BsonIterTypeName(updateIter)))); |
| 1000 | } |
| 1001 | |
| 1002 | update = palloc(sizeof(bson_value_t)); |
| 1003 | *update = *bson_iter_value(updateIter); |
| 1004 | } |
| 1005 | else if (strcmp(field, "multi") == 0) |
| 1006 | { |
| 1007 | EnsureTopLevelFieldType("update.updates.multi", updateIter, BSON_TYPE_BOOL); |
| 1008 | |
| 1009 | isMulti = bson_iter_bool(updateIter); |
| 1010 | } |
| 1011 | else if (strcmp(field, "upsert") == 0) |
| 1012 | { |
| 1013 | EnsureTopLevelFieldType("update.updates.upsert", updateIter, BSON_TYPE_BOOL); |
| 1014 | |
| 1015 | isUpsert = bson_iter_bool(updateIter); |
| 1016 | } |
| 1017 | else if (strcmp(field, "arrayFilters") == 0) |
| 1018 | { |
| 1019 | EnsureTopLevelFieldType("update.updates.arrayFilters", updateIter, |
| 1020 | BSON_TYPE_ARRAY); |
| 1021 | |
| 1022 | |
| 1023 | arrayFilters = palloc(sizeof(bson_value_t)); |
| 1024 | *arrayFilters = *bson_iter_value(updateIter); |
| 1025 | } |
| 1026 | else if (strcmp(field, "collation") == 0) |
| 1027 | { |
no test coverage detected