Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Atlas

$collStats

On this page

  • Syntax
  • Fields
  • Output
  • Examples
  • Errors

$collStats returns statistics for a given collection. $collstats must be the first stage in the aggregation pipeline. For more information, see $collStats. In Data Federation, $collStats can only be used to retrieve information about the partitions for a given collection or view.

In Atlas Data Federation, $collStats accepts an empty document. It supports the optional field count only and returns an error if an unsupported option is specified.

db.<collection-name>|<view-name>.aggregate([{ "$collStats" : { "count" : {} } }])
Field
type
Description
Necessity
count
document
Adds the total number of documents in the partitions to the return document.
Optional

$collStats returns the following fields in the document for each partition:

Field
Type
Description
count
number
The total number of documents in the partition. This is returned only if you specify the count option.
ns
string
The namespace of the current collection or view in the format [database].[collection|view].
partition
document
The details about the partition such as the source, format, size, and partition attributes, if any.
partition.format
string
The format of the file. Value can be any of the Supported Data Formats for data in S3 bucket or MONGO for data in the Atlas cluster.
partition.attributes
document
The partition attributes for this partition defined in the path for S3 partitions. An empty document indicates that there are no partition attributes in the partition's data source.
partition.size
int
The size of the partition.
partition.source
string

The source for the partition. The value can be one of the following:

  • The path to the file on S3.

  • The cluster name for partitions on Atlas.

partition.version
string

MongoDB version of the Atlas cluster. The $collStats stage returns this field only for Atlas cluster data stores. The value has the following format:

<major-version-number>.<minor-version-number>.<patch-version-number>

For example, 7.0.1.

An error similar to the following is returned if the collStats argument document contains any of the options allowed by the MongoDB server but not by Atlas Data Federation.

{
"ok" : 0,
"errmsg" : "$collStats param 'latencyStats' is not valid for Data Lake, correlationID = 1622929884a47d16f4888a1c",
"code" : 9,
"codeName" : "FailedToParse"
}
←  Supported Aggregation Pipeline Stages and Operators$lookup →