When I check the slow queries in my database, I find the following aggregate query being executed on multiple collections:
[
{
"$addFields": {
"temporary_doc_size_field": {
"$bsonSize": "$$ROOT"
}
}
},
{
"$match": {
"temporary_doc_size_field": {
"$lt": 16793600
}
}
},
{
"$project": {
"temporary_doc_size_field": 0
}
},
{
"$sample": {
"size": 1000
}
}
]
It performs a collection scan and reads a lot into the disk. I checked my application and couldn’t find this query in the source code.
So, is this aggregate query automatically executed by MongoDB, and what is its purpose? Is there any way to limit it because it is quite costly in terms of disk I/O?