dataSize

Definition

  • dataSize
  • The dataSize command returns the data size for a setof data within a certain range:
  1. {
  2. dataSize: <string>,
  3. keyPattern: <document>,
  4. min: <document>,
  5. max: <document>,
  6. estimate: <boolean>
  7. }

The command takes the following fields:

FieldTypeDescriptiondataSizestringThe name of the target collection.keyPatterndocumentOptional. The collection’s key pattern to examine.

The collection must have an index with the corresponding pattern.Otherwise dataSize returns an error message.mindocumentOptional. The lower bound of the key range to be examined.maxdocumentOptional. The upper bound of the key range to be examined.estimatebooleanOptional. When true, dataSize estimates the data size byassuming that all documents in the specified range are uniformlysized as per the collection’s average object size. The collection’saverage object size is obtained from the avgObjSize field inthe output of the collStats command.

Defaults to false.

Example

The following operation runs the dataSize command on thedatabase.collection collection, specifying a key pattern of {field: 1}with the lower bound of the range of keys to be examined being {field: 10}and the upper bound of the key to be examined being {field: 100}.

  1. db.runCommand({ dataSize: "database.collection", keyPattern: { field: 1 }, min: { field: 10 }, max: { field: 100 } })

This will return a document that contains the size of all matchingdocuments. Replace database.collection value with databaseand collection from your deployment.

The amount of time required to return dataSize depends on theamount of data in the collection.