@@ -25,7 +25,7 @@ Definition
25
25
26
26
.. code-block:: none
27
27
28
- [ [ "item", "abc123"], [ "qty", 25 ] ]
28
+ [ [ [ "item", "abc123" ], [ "qty", 25 ] ] ]
29
29
30
30
\- OR -
31
31
@@ -38,7 +38,7 @@ Definition
38
38
39
39
.. code-block:: none
40
40
41
- [ { "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 } ]
41
+ [ [ { "k": "item", "v": "abc123" }, { "k": "qty", "v": 25 } ] ]
42
42
43
43
:expression:`$arrayToObject` has the following syntax:
44
44
@@ -70,7 +70,7 @@ If the name of a field repeats in the array,
70
70
71
71
.. list-table::
72
72
:header-rows: 1
73
- :widths: 80 20
73
+ :widths: 60 40
74
74
:class: border-table
75
75
76
76
* - Example
@@ -79,21 +79,24 @@ If the name of a field repeats in the array,
79
79
* - .. code-block:: json
80
80
:copyable: false
81
81
82
- { $arrayToObject: { $literal: [
83
- { "k": "item", "v": "abc123"},
84
- { "k": "qty", "v": 25 }
85
- ] } }
82
+ { $arrayToObject: [
83
+ [ { "k": "item", "v": "abc123" },
84
+ { "k": "qty", "v": "$qty" } ]
85
+ ] }
86
86
87
- - .. code-block:: json
88
- :copyable: false
87
+ - Given a document with the field ``qty`` and value ``25``,
88
+ :expression:`$arrayToObject` returns:
89
89
90
+ .. code-block:: json
91
+ :copyable: false
92
+
90
93
{ "item" : "abc123", "qty" : 25 }
91
94
92
95
* - .. code-block:: json
93
96
:copyable: false
94
97
95
98
{ $arrayToObject: { $literal: [
96
- [ "item", "abc123"], [ "qty", 25 ]
99
+ [ "item", "abc123" ], [ "qty", 25 ]
97
100
] } }
98
101
99
102
- .. code-block:: json
@@ -105,7 +108,7 @@ If the name of a field repeats in the array,
105
108
:copyable: false
106
109
107
110
{ $arrayToObject: { $literal: [
108
- { "k": "item", "v": "123abc"},
111
+ { "k": "item", "v": "123abc" },
109
112
{ "k": "item", "v": "abc123" }
110
113
] } }
111
114
0 commit comments