feat(shell-api): use collStats aggregation stage instead of command for collection.stats() MONGOSH-1157 #1384
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MONGOSH-1157
This PR updates our
db.collection.stats()
shell api method to use the aggregation stage$collStats
for fetching collection statistics instead of thedb.runCommand({ collStats: collectionName })
form. The run command form is to be deprecated by 7.0 (PM-2362)The
$collStats
stage returns a document for each individual shard's statistics. A lot of the code of this pr involves aggregating those documents into one document to be returned. I initially was trying to do this all in one aggregation pipeline, however I found it was going to be a bit harder to test and maintain. Things like new keys likenumOrphanDocs
added in 6.0 make an aggregation a lot more complex. If curious a fairly non-optimized implementation (withouttimeseries
support) can be found on this gist: https://gist.github.com/Anemy/1e3b38f8f4f07f055a8c18d4b6ab443bThe
$collStats
aggregation stage fails on sharded timeseries collections so we fallback to the old command form when that error code is encountered.Notes
db.collection.stats()
Using the aggregation $collStats stage does not return the same data
as the soon to be deprecated collStats command. Namely:
-
primary
is not given now.-
nchunks
is not given now.These fields already aren't listed in our documentation: https://www.mongodb.com/docs/manual/reference/command/collStats/ but I'm curious to hear if folks feel we should work to re-add them or have more insights.