@@ -1020,7 +1020,8 @@ The structure of this object is as follows:
1020
1020
The structure of this object is as follows :
1021
1021
1022
1022
- `command` : Optional document. A value corresponding to the expected command document. Test runners MUST follow the
1023
- rules in [Evaluating Matches](#evaluating-matches) when processing this assertion.
1023
+ rules in [Evaluating Matches](#evaluating-matches) when processing this assertion and match the value as a
1024
+ root-level document.
1024
1025
- `commandName` : Optional string. Test runners MUST assert that the command name matches this value.
1025
1026
- `databaseName` : Optional string. Test runners MUST assert that the database name matches this value. The YAML file
1026
1027
SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for this value (e.g.
@@ -1036,7 +1037,8 @@ The structure of this object is as follows:
1036
1037
The structure of this object is as follows :
1037
1038
1038
1039
- `reply` : Optional document. A value corresponding to the expected reply document. Test runners MUST follow the rules
1039
- in [Evaluating Matches](#evaluating-matches) when processing this assertion.
1040
+ in [Evaluating Matches](#evaluating-matches) when processing this assertion and match the value as a root-level
1041
+ document.
1040
1042
- `commandName` : Optional string. Test runners MUST assert that the command name matches this value.
1041
1043
- `databaseName` : Optional string. Test runners MUST assert that the database name matches this value. The YAML file
1042
1044
SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for this value (e.g.
@@ -1663,6 +1665,10 @@ below.
1663
1665
When executing an `aggregate` operation, the test runner MUST fully iterate the result. This will ensure consistent
1664
1666
behavior between drivers that eagerly create a server-side cursor and those that do so lazily when iteration begins.
1665
1667
1668
+ When evaluating the iterated result for [expectResult](#operation_expectResult), the number of actual and expected
1669
+ documents MUST be equal and each document value within the `expectResult` array MUST be matched as a root-level document
1670
+ (for [Evaluating Matches](#evaluating-matches)).
1671
+
1666
1672
# ### bulkWrite
1667
1673
1668
1674
These considerations only apply to the `MongoCollection.bulkWrite` method. See [clientBulkWrite](#clientbulkwrite) for
@@ -1765,12 +1771,19 @@ This operation proxies the collection's `dropSearchIndex` helper with the same a
1765
1771
When executing a `find` operation, the test runner MUST fully iterate the result. This will ensure consistent behavior
1766
1772
between drivers that eagerly create a server-side cursor and those that do so lazily when iteration begins.
1767
1773
1774
+ When evaluating the iterated result for [expectResult](#operation_expectResult), the number of actual and expected
1775
+ documents MUST be equal and each document value within the `expectResult` array MUST be matched as a root-level document
1776
+ (for [Evaluating Matches](#evaluating-matches)).
1777
+
1768
1778
# ### findOneAndReplace and findOneAndUpdate
1769
1779
1770
1780
The `returnDocument` option for `findOneAndReplace` and `findOneAndUpdate` is documented as an enum with possible values
1771
1781
" Before" and "After". Test files SHOULD express `returnDocument` as a string and test runners MUST raise an error if its
1772
1782
value does not case-insensitively match either enum value.
1773
1783
1784
+ When evaluating the result for [expectResult](#operation_expectResult), the document MUST be matched as a root-level
1785
+ document (for [Evaluating Matches](#evaluating-matches)).
1786
+
1774
1787
# ### insertMany
1775
1788
1776
1789
The CRUD spec documents `insertMany` as returning a BulkWriteResult. Because the `insertedIds` field of BulkWriteResult
@@ -1897,7 +1910,8 @@ first position (e.g. `rewind` in PHP).
1897
1910
# ### iterateUntilDocumentOrError
1898
1911
1899
1912
Iterates the cursor until either a single document is returned or an error is raised. This operation takes no arguments.
1900
- If [expectResult](#operation_expectResult) is specified, it SHOULD be a single document.
1913
+ If [expectResult](#operation_expectResult) is specified, it SHOULD be a single document and MUST be matched as a
1914
+ root-level document according to the rules in [Evaluating Matches](#evaluating-matches).
1901
1915
1902
1916
Some specification sections (e.g.
1903
1917
[Iterating the Change Stream](../change-streams/tests/README.md#iterating-the-change-stream)) caution drivers that
@@ -2709,15 +2723,7 @@ actual value of `1.0` (e.g. `ok` field in a server response) but would not match
2709
2723
# ### Allowing Extra Fields in Root-level Documents
2710
2724
2711
2725
When matching root-level documents, test runners MUST permit the actual document to contain additional fields not
2712
- present in the expected document. Examples of root-level documents include, but are not limited to :
2713
-
2714
- - ` command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)
2715
- - ` reply` for [CommandSucceededEvent](#expectedEvent_commandSucceededEvent)
2716
- - [expectResult](#operation_expectResult) for `findOneAndUpdate` [Collection Operations](#collection-operations)
2717
- - [expectResult](#operation_expectResult) for [iterateUntilDocumentOrError](#iterateuntildocumentorerror)
2718
- - [expectedError_errorResponse](#expectedError_errorResponse)
2719
- - each array element in [expectResult](#operation_expectResult) for [find](#find) or
2720
- [collection_aggregate](#collection_aggregate) [Collection Operations](#collection-operations)
2726
+ present in the expected document.
2721
2727
2722
2728
For example, the following documents match :
2723
2729
@@ -2745,15 +2751,47 @@ is not always feasible or relevant for a test to exhaustively specify all fields
2745
2751
time in `command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)).
2746
2752
2747
2753
When the expected value is an array, test runners MUST differentiate between an array of values, which may be documents,
2748
- (e.g. `distinct`) and an array of root-level documents (e.g. `find`, `aggregate`). For example, the following array of
2749
- documents would not match if returned by `distinct`, but would match if returned via `find` (after iterating the
2750
- cursor) :
2754
+ (e.g. `distinct`) and an array of root-level documents derived from an iterable result (e.g. `find`, `aggregate`). For
2755
+ example, the following array of documents would not match if returned by `distinct`, but would match if returned via
2756
+ `find` (after iterating the cursor) :
2751
2757
2752
2758
` ` ` yaml
2753
2759
expected: [ { x: 1 }, { x: 2 } ]
2754
2760
actual: [ { x: 1, y: 1 }, { x: 2, y: 2 } ]
2755
2761
` ` `
2756
2762
2763
+ # #### Examples of Root-level Documents
2764
+
2765
+ Contexts where one might encounter a root-level document include :
2766
+
2767
+ - ` command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)
2768
+
2769
+ - ` reply` for [CommandSucceededEvent](#expectedEvent_commandSucceededEvent)
2770
+
2771
+ - [expectResult](#operation_expectResult) for operations that return a document. Operations include:
2772
+
2773
+ - findOneAndDelete, [findOneAndReplace](#findoneandreplace-and-findoneandupdate), and
2774
+ [findOneAndUpdate](#findoneandreplace-and-findoneandupdate)
2775
+ - [iterateUntilDocumentOrError](#iterateuntildocumentorerror)
2776
+ - [iterateOnce](#iterateonce)
2777
+
2778
+ - [expectResult](#operation_expectResult) array elements for operations that return an iterable of documents. Operations
2779
+ include :
2780
+
2781
+ - [aggregate](#aggregate)
2782
+ - [find](#find))
2783
+ - [listCollections](#listcollections), listDatabases, and listIndexes
2784
+ - [listSearchIndexes](#listsearchindexes)
2785
+ - [runCursorCommand](#runcursorcommand)
2786
+
2787
+ - [errorResponse](#expectedError_errorResponse) for [expectedError](#expectederror)
2788
+
2789
+ - ` writeErrors` object values for [expectedError](#expectederror)
2790
+
2791
+ - ` writeConcernErrors` array elements for [expectedError](#expectederror)
2792
+
2793
+ - ` data` for [expectedLogMessage](#expectedlogmessage)
2794
+
2757
2795
# ### Document Key Order Variation
2758
2796
2759
2797
When matching documents, test runners MUST NOT require keys in the expected and actual document to appear in the same
@@ -2861,6 +2899,8 @@ the test runner MUST fetch that entity and assert that the actual value matches
2861
2899
[Evaluating Matches](#evaluating-matches); otherwise, the test runner MUST raise an error for an undefined or mistyped
2862
2900
entity. The YAML file SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for the entity name.
2863
2901
2902
+ This operator does not influence whether or not an actual document value is considered a root-level document.
2903
+
2864
2904
This operator is primarily used to assert identifiers for uploaded GridFS files.
2865
2905
2866
2906
An example of this operator follows :
@@ -2911,6 +2951,8 @@ excluding an array element because
2911
2951
MUST assert that the actual value either does not exist or matches the expected value. Matching the expected value MUST
2912
2952
use the standard rules in [Evaluating Matches](#evaluating-matches), which means that it may contain special operators.
2913
2953
2954
+ This operator does not influence whether or not an actual document value is considered a root-level document.
2955
+
2914
2956
This operator is primarily used to assert driver-optional fields from the CRUD spec (e.g. `insertedId` for
2915
2957
InsertOneResult, `writeResult` for BulkWriteException).
2916
2958
@@ -2980,9 +3022,13 @@ Syntax:
2980
3022
2981
3023
This operator may be used anywhere a matched value is expected (including [expectResult](#operation_expectResult)) and
2982
3024
the actual value is an extended JSON string. The test runner MUST parse the actual value into a BSON document and match
2983
- it against the expected value. Matching the expected value MUST use the standard rules in
2984
- [Evaluating Matches](#evaluating-matches), which means that it may contain special operators. This operator is primarily
2985
- used to assert on extended JSON commands and command replies included in log messages.
3025
+ it against the expected value.
3026
+
3027
+ Matching the expected value MUST use the standard rules in [Evaluating Matches](#evaluating-matches), which means that
3028
+ it may contain special operators. The actual value MUST NOT be considered a root-level document (i.e. extra fields are
3029
+ not permitted); however, [$$matchAsRoot](#matchasroot) may be used to change that behavior.
3030
+
3031
+ This operator is primarily used to assert on extended JSON commands and command replies included in log messages.
2986
3032
2987
3033
# #### $$matchAsRoot
2988
3034
@@ -3505,6 +3551,8 @@ other specs *and* collating spec changes developed in parallel or during the sam
3505
3551
3506
3552
# # Changelog
3507
3553
3554
+ - 2024-10-29 : List more examples of root-level documents
3555
+
3508
3556
- 2024-10-24 : Document `namespace` option for `failCommand` fail point.
3509
3557
3510
3558
- 2024-09-18 : Note that `failCommand` `appName` option was backported
0 commit comments