| 1353 | }; |
| 1354 | |
| 1355 | struct ExtReplaceUpdate : ConcreteUpdateOp<ExtReplaceUpdate> { |
| 1356 | bson::BSONObj replaceWith; |
| 1357 | |
| 1358 | explicit ExtReplaceUpdate(bson::BSONObj const& replaceWith) : replaceWith(replaceWith) {} |
| 1359 | |
| 1360 | Future<Void> update(Reference<IReadWriteContext> document) override { return replacementActor(this, document); } |
| 1361 | |
| 1362 | std::string describe() override { return "ReplaceWith(" + replaceWith.toString() + ")"; } |
| 1363 | |
| 1364 | ACTOR static Future<Void> replacementActor(ExtReplaceUpdate* self, Reference<IReadWriteContext> document) { |
| 1365 | state Standalone<StringRef> keyEncodedId = wait(document->getKeyEncodedId()); |
| 1366 | Optional<IdInfo> encodedIds = extractEncodedIds(self->replaceWith); |
| 1367 | if (encodedIds.present() && encodedIds.get().keyEncoded != keyEncodedId) { |
| 1368 | throw replace_with_id(); |
| 1369 | } |
| 1370 | |
| 1371 | Optional<DataValue> iddv2 = |
| 1372 | wait(document->get(DataValue(DocLayerConstants::ID_FIELD, DVTypeCode::STRING).encode_key_part())); |
| 1373 | document->clearDescendants(); |
| 1374 | |
| 1375 | if (iddv2.get().getBSONType() == bson::BSONType::Object) { |
| 1376 | DataValue iddv = DataValue::decode_key_part(keyEncodedId); |
| 1377 | if (iddv.getBSONType() == bson::BSONType::Object) { |
| 1378 | insertElementRecursive(iddv.wrap(DocLayerConstants::ID_FIELD).getField(DocLayerConstants::ID_FIELD), |
| 1379 | document); |
| 1380 | } |
| 1381 | } else { |
| 1382 | document->set(DataValue(DocLayerConstants::ID_FIELD, DVTypeCode::STRING).encode_key_part(), |
| 1383 | iddv2.get().encode_value()); |
| 1384 | } |
| 1385 | |
| 1386 | for (auto i = self->replaceWith.begin(); i.more();) { |
| 1387 | auto e = i.next(); |
| 1388 | insertElementRecursive(e, document); |
| 1389 | } |
| 1390 | document->set(StringRef(), DataValue::subObject().encode_value()); |
| 1391 | return Void(); |
| 1392 | } |
| 1393 | }; |
| 1394 | |
| 1395 | struct ExtOperatorUpsert : ConcreteInsertOp<ExtOperatorUpsert> { |
| 1396 | bson::BSONObj selector; |
nothing calls this directly
no outgoing calls
no test coverage detected