I have a Mongo database with a collection with 1 billion rows. Each document has three fields, _id, Input and Hash. There are indexes on each of these fields.
I'm attempting to run the following query:
db.Collection.aggregate([ { "$group" : { _id : "$Input", count : { $sum : 1 } } }, { "$sort" : { "count" : -1 } }, { "$match" : { "count" : { "$gt" : 1 } } } ], { "allowDiskUse" : true } )
I've tried to run it a few times and it runs for a few hours and then errors with:
QUERY [js] uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "assertion src/mongo/db/pipeline/value.cpp:1365",
"code" : 8,
"codeName" : "UnknownError"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:583:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12
What's going on here?
DB version is 4.1.2
$group
stage doesn't use any indexes (see Mongodb Aggregation Framework: Does $group use index?). You can verify if any indexes are used with the query by running theexplain
on the aggregation.