12
12
:depth: 2
13
13
:class: singlecol
14
14
15
- ``$collStats`` returns statistics for a given collection. ``$collstats`` must
16
- be the first stage in the aggregation pipeline. For more information,
17
- see :manual:`$collStats </reference/operator/aggregation/collStats/>`. In
18
- {+data-lake+}, ``$collStats`` can only be used to retrieve information about the
15
+ ``$collStats`` returns statistics for a given collection.
16
+ ``$collstats`` must be the first stage in the aggregation pipeline. For
17
+ more information, see :manual:`$collStats
18
+ </reference/operator/aggregation/collStats/>`. In {+dl+},
19
+ ``$collStats`` can only be used to retrieve information about the
19
20
partitions for a given collection or view.
20
21
21
22
.. _adl-collstats-syntax:
22
23
23
24
Syntax
24
25
------
25
26
26
- In {+adl+}, :manual:`$collStats </reference/operator/aggregation/collStats/>`
27
- accepts an empty document. It does not support any of the optional fields
28
- supported by the MongoDB server and returns an error if an unsupported option
29
- is specified.
27
+ In {+adl+}, :manual:`$collStats
28
+ </reference/operator/aggregation/collStats/>` accepts an empty
29
+ document. It supports the optional field ``count`` only and returns
30
+ an error if an unsupported option is specified.
30
31
31
32
.. code-block:: sh
32
33
33
- db.<collection-name>|<view-name>.aggregate([{ "$collStats" : {} }])
34
+ db.<collection-name>|<view-name>.aggregate([{ "$collStats" : { "count" : {} } }])
35
+
36
+ .. _adl-collstats-fields:
37
+
38
+ Fields
39
+ ------
40
+
41
+ .. list-table::
42
+ :header-rows: 1
43
+ :widths: 10 10 70 10
44
+
45
+ * - Field
46
+ - type
47
+ - Description
48
+ - Necessity
49
+
50
+ * - ``count``
51
+ - document
52
+ - Adds the total number of documents in the partitions to the
53
+ return document.
54
+ - Optional
34
55
35
56
.. _adl-collstats-output:
36
57
37
58
Output
38
59
------
39
60
40
- ``$collStats`` returns the following fields in the document for each partition:
61
+ ``$collStats`` returns the following fields in the document for each
62
+ partition:
41
63
42
64
.. list-table::
43
65
:header-rows: 1
@@ -47,37 +69,44 @@ Output
47
69
- Type
48
70
- Description
49
71
72
+ * - ``count``
73
+ - number
74
+ - The total number of documents in the partition. This is returned
75
+ only if you specify the ``count`` option.
76
+
50
77
* - ``ns``
51
78
- string
52
79
- The namespace of the current collection or view in the format
53
80
``[database].[collection|view]``.
54
81
55
82
* - ``partition``
56
83
- document
57
- - The details about the partition such as the source, format, size, and
58
- :ref:`partition attributes <datalake-path-attribute-types>`, if any.
84
+ - The details about the partition such as the source, format,
85
+ size, and :ref:`partition attributes
86
+ <datalake-path-attribute-types>`, if any.
59
87
60
88
* - ``partition.format``
61
89
- string
62
90
- The format of the file. Value can be any of the
63
- :ref:`data-lake-data-formats` for data in |s3| bucket or ``MONGO`` for
64
- data in the |service| cluster.
91
+ :ref:`data-lake-data-formats` for data in |s3| bucket or
92
+ ``MONGO`` for data in the |service| cluster.
65
93
66
94
* - ``partition.attributes``
67
95
- document
68
- - The :ref:`partition attributes <datalake-path-attribute-types>` for this
69
- partition defined in the
70
- :datalakeconf:`~databases.[n].collections.[n].dataSources.[n].path` for
71
- |s3| partitions. An empty document indicates that there are no partition
72
- attributes in the partition's data source.
96
+ - The :ref:`partition attributes <datalake-path-attribute-types>`
97
+ for this partition defined in the
98
+ :datalakeconf:`~databases.[n].collections.[n].dataSources.[n].
99
+ path` for |s3| partitions. An empty document indicates that
100
+ there are no partition attributes in the partition's data source.
73
101
74
102
* - ``partition.size``
75
103
- int
76
104
- The size of the partition.
77
105
78
106
* - ``partition.source``
79
107
- string
80
- - The source for the partition. The value can be one of the following:
108
+ - The source for the partition. The value can be one of the
109
+ following:
81
110
82
111
- The path to the file on |s3|.
83
112
- The cluster name for partitions on |service|.
@@ -87,50 +116,75 @@ Output
87
116
Examples
88
117
--------
89
118
90
- The following example shows :manual:`$collStats
91
- </reference/operator/aggregation/collStats/>` syntax for retrieving the
92
- partitions from a ``s3Db.abc`` collection with 3 files in an |s3|
93
- {+data-lake-store+}:
119
+ .. tabs::
94
120
95
- .. code-block:: sh
121
+ .. tab:: Basic Example
122
+ :tabid: basic
96
123
97
- use s3Db
98
- db.abc.aggregate([ {$collStats: {}} ])
124
+ The following example shows :manual:`$collStats
125
+ </reference/operator/aggregation/collStats/>` syntax for
126
+ retrieving the partitions from a ``s3Db.abc`` collection with 3
127
+ files in an |s3| {+data-lake-store+}:
99
128
100
- The preceding command returns the following output:
129
+ .. code-block:: sh
101
130
102
- .. code-block:: json
103
- :copyable: false
131
+ use s3Db
132
+ db.abc.aggregate([ {$collStats: {}} ])
104
133
105
- { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2018) }, "size" : 139, "source" : "s3://my-bucket/s3Db/abc/2018/1.json?delimiter=%2F®ion=us-east-1" } }
106
- { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2017) }, "size" : 124, "source" : "s3://my-bucket/s3Db/abc/2017/1.json?delimiter=%2F®ion=us-east-1" } }
107
- { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2017) }, "size" : 130, "source" : "s3://my-bucket/s3Db/abc/2017/2.json?delimiter=%2F®ion=us-east-1" } }
134
+ The preceding command returns the following output:
108
135
109
- The following example shows :manual:`$collStats
110
- </reference/operator/aggregation/collStats/>` syntax for retrieving the
111
- partitions from the ``atlasDb.sampleColl`` collection in the |service| cluster
112
- named ``mySandboxCluster``:
136
+ .. code-block:: json
137
+ :copyable: false
113
138
114
- .. code-block:: sh
139
+ { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2018) }, "size" : 139, "source" : "s3://my-bucket/s3Db/abc/2018/1.json?delimiter=%2F®ion=us-east-1" } }
140
+ { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2017) }, "size" : 124, "source" : "s3://my-bucket/s3Db/abc/2017/1.json?delimiter=%2F®ion=us-east-1" } }
141
+ { "ns" : "s3Db.abc", "partition" : { "format" : "JSON", "attributes" : { "year" : NumberLong(2017) }, "size" : 130, "source" : "s3://my-bucket/s3Db/abc/2017/2.json?delimiter=%2F®ion=us-east-1" } }
115
142
116
- use atlasDb
117
- db.sampleColl.aggregate([ {$collStats: {}} ])
143
+ The following example shows :manual:`$collStats
144
+ </reference/operator/aggregation/collStats/>` syntax for
145
+ retrieving the partitions from the ``atlasDb.sampleColl``
146
+ collection in the |service| cluster named ``mySandboxCluster``:
118
147
119
- The preceding command returns the following output:
148
+ .. code-block:: sh
120
149
121
- .. code-block:: json
122
- :copyable: false
150
+ use atlasDb
151
+ db.sampleColl.aggregate([ {$collStats: {}} ])
152
+
153
+ The preceding command returns the following output:
154
+
155
+ .. code-block:: json
156
+ :copyable: false
157
+
158
+ { "ns" : "atlasDb.sampleColl", "partition" : { "format" : "MONGO", "attributes" : { }, "size" : 94362191, "source" : "mySandboxCluster" } }
159
+
160
+ .. tab:: Count Example
161
+ :tabid: count
162
+
163
+ The following example shows :manual:`$collStats
164
+ </reference/operator/aggregation/collStats/>` syntax for
165
+ retrieving the total number of documents in the partitions.
166
+
167
+ .. code-block:: sh
168
+
169
+ use s3Db
170
+ db.abc.aggregate([ {$collStats: {"count" : {} }} ])
171
+
172
+ The preceding command returns the following output:
173
+
174
+ .. code-block:: json
175
+ :copyable: false
123
176
124
- { "ns" : "atlasDb.sampleColl", "partition" : { "format" : "MONGO", "attributes" : { }, "size" : 94362191, "source" : "mySandboxCluster" } }
177
+ { "ns" : "atlasDb.sampleColl", "partition" : { "format" : "MONGO", "attributes" : { }, "size" : 94362191, "source" : "mySandboxCluster" }, "count" : 23530 }
125
178
126
179
.. _adl-collstats-errors:
127
180
128
181
Errors
129
182
------
130
183
131
184
An error similar to the following is returned if the :manual:`collStats
132
- </reference/operator/aggregation/collStats/>` argument document contains
133
- any of the options allowed by the MongoDB server but not by {+adl+}.
185
+ </reference/operator/aggregation/collStats/>` argument document
186
+ contains any of the options allowed by the MongoDB server but not by
187
+ {+adl+}.
134
188
135
189
.. code-block:: json
136
190
:copyable: false
0 commit comments