* BsonUnwindEmptyArray produces the output document when an empty array is found * at the unwind target * document -> source document * path -> path being unwound * indexFieldName -> optional name for the index field to be added */
| 493 | * indexFieldName -> optional name for the index field to be added |
| 494 | */ |
| 495 | static pgbson * |
| 496 | BsonUnwindEmptyArray(pgbson *document, char *path, char *indexFieldName) |
| 497 | { |
| 498 | pgbson_writer projectSpecWriter; |
| 499 | PgbsonWriterInit(&projectSpecWriter); |
| 500 | |
| 501 | bool value = false; |
| 502 | PgbsonWriterAppendBool(&projectSpecWriter, path, strlen(path), |
| 503 | value); |
| 504 | |
| 505 | if (indexFieldName != NULL) |
| 506 | { |
| 507 | /* Single elements have null index */ |
| 508 | PgbsonWriterAppendNull(&projectSpecWriter, indexFieldName, strlen( |
| 509 | indexFieldName)); |
| 510 | } |
| 511 | |
| 512 | bson_iter_t projectSpec; |
| 513 | PgbsonWriterGetIterator(&projectSpecWriter, &projectSpec); |
| 514 | |
| 515 | bool forceProjectId = true; |
| 516 | bool allowInclusionExclusion = true; |
| 517 | |
| 518 | pgbson *variableSpec = NULL; |
| 519 | const BsonProjectionQueryState *projectionState = |
| 520 | GetProjectionStateForBsonProject(&projectSpec, |
| 521 | forceProjectId, allowInclusionExclusion, |
| 522 | variableSpec); |
| 523 | return ProjectDocumentWithState(document, projectionState); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | /* |
no test coverage detected