[DOCS-10476] Document whether $indexStats is required to be the first pipeline operator Created: 30/Jun/17  Updated: 30/Oct/23  Resolved: 19/Jul/17

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Improvement Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Allison Reinheimer Moore
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 6 years, 30 weeks ago

 Description   

Docs for $collStats states:

$collStats must be the first stage in an aggregation pipeline, or else the pipeline returns an error.

This is not mentioned for $indexStats, but I gather both operators are similar. If $indexStats has a similar restriction, we should document it.



 Comments   
Comment by Allison Reinheimer Moore [ 19/Jul/17 ]

Patch: https://github.com/mongodb/docs/commit/8745ac8164e33d800cda31a7928a2dd165431e27 (I typod the issue number in the commit, hence the lack of linking).

Comment by Allison Reinheimer Moore [ 04/Jul/17 ]

This does appear to be the case for $indexStats!

> db.restaurants.aggregate([{$match: {borough: "Queens"}}, {$indexStats: {} }])
assert: command failed: {
	"ok" : 0,
	"errmsg" : "$indexStats is only valid as the first stage in a pipeline.",
	"code" : 28837
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:290:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1312:5
@(shell):1:1

Generated at Thu Feb 08 08:00:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.