* Handles the projection of an array field for the $redact stage. * There is a recursive call to EvaluateRedactDocument for nested * documents and recursive calls to EvaluateRedactArray for nested arrays. */
| 1472 | * documents and recursive calls to EvaluateRedactArray for nested arrays. |
| 1473 | */ |
| 1474 | static void |
| 1475 | EvaluateRedactArray(const bson_value_t *array, const BsonReplaceRootRedactState *state, |
| 1476 | pgbson_array_writer *array_Writer) |
| 1477 | { |
| 1478 | /* recursively evaluate nested documents in array */ |
| 1479 | bson_iter_t arrayIter; |
| 1480 | BsonValueInitIterator(array, &arrayIter); |
| 1481 | |
| 1482 | while (bson_iter_next(&arrayIter)) |
| 1483 | { |
| 1484 | const bson_value_t *arrayElement = bson_iter_value( |
| 1485 | &arrayIter); |
| 1486 | if (BSON_ITER_HOLDS_DOCUMENT(&arrayIter)) |
| 1487 | { |
| 1488 | bool shouldPrune = false; |
| 1489 | pgbson *nestedDocument = EvaluateRedactDocument( |
| 1490 | PgbsonInitFromDocumentBsonValue(arrayElement), state, &shouldPrune); |
| 1491 | if (!shouldPrune) |
| 1492 | { |
| 1493 | PgbsonArrayWriterWriteDocument(array_Writer, |
| 1494 | nestedDocument); |
| 1495 | } |
| 1496 | } |
| 1497 | else if (BSON_ITER_HOLDS_ARRAY(&arrayIter)) |
| 1498 | { |
| 1499 | pgbson_array_writer child_array_writer; |
| 1500 | PgbsonArrayWriterStartArray(array_Writer, |
| 1501 | &child_array_writer); |
| 1502 | EvaluateRedactArray(arrayElement, state, &child_array_writer); |
| 1503 | PgbsonArrayWriterEndArray(array_Writer, &child_array_writer); |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | PgbsonArrayWriterWriteValue(array_Writer, |
| 1508 | arrayElement); |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | /* |
no test coverage detected