| 1393 | }; |
| 1394 | |
| 1395 | struct ExtOperatorUpsert : ConcreteInsertOp<ExtOperatorUpsert> { |
| 1396 | bson::BSONObj selector; |
| 1397 | bson::BSONObj update; |
| 1398 | |
| 1399 | ExtOperatorUpsert(bson::BSONObj selector, bson::BSONObj update) : selector(selector), update(update) {} |
| 1400 | |
| 1401 | ACTOR static Future<Reference<IReadWriteContext>> upsertActor(ExtOperatorUpsert* self, |
| 1402 | Reference<CollectionContext> cx) { |
| 1403 | Optional<IdInfo> encodedIds = extractEncodedIds(self->selector); |
| 1404 | if (!encodedIds.present()) |
| 1405 | encodedIds = extractEncodedIdsFromUpdate(self->update); |
| 1406 | int selectorOperators = hasOperatorFieldnames(self->selector, -1, 0); |
| 1407 | bson::BSONObj thingToInsert; |
| 1408 | if (!selectorOperators) { |
| 1409 | thingToInsert = self->selector; |
| 1410 | } else { |
| 1411 | thingToInsert = transformOperatorQueryToUpdatableDocument(self->selector); |
| 1412 | } |
| 1413 | state Reference<IReadWriteContext> dcx = wait(insertDocument(cx, thingToInsert, encodedIds)); |
| 1414 | wait(updateDocument(dcx, self->update, true, dcx->getKeyEncodedId())); |
| 1415 | return dcx; |
| 1416 | } |
| 1417 | |
| 1418 | Future<Reference<IReadWriteContext>> insert(Reference<CollectionContext> cx) override { |
| 1419 | return upsertActor(this, cx); |
| 1420 | } |
| 1421 | |
| 1422 | std::string describe() override { return "OperatorUpsert(" + selector.toString() + "," + update.toString() + ")"; } |
| 1423 | }; |
| 1424 | |
| 1425 | struct ExtSimpleUpsert : ConcreteInsertOp<ExtSimpleUpsert> { |
| 1426 | bson::BSONObj selector; |
nothing calls this directly
no outgoing calls
no test coverage detected