Skip to content

Instantly share code, notes, and snippets.

@dzhuryn
Last active May 14, 2023 17:13
Show Gist options
  • Save dzhuryn/1a4358b1d0356d861c0b8be9f5675c69 to your computer and use it in GitHub Desktop.
Save dzhuryn/1a4358b1d0356d861c0b8be9f5675c69 to your computer and use it in GitHub Desktop.
test
db.threads
//.explain("executionStats")
.aggregate([
{
"$match": {
"ci": {
"$in": [
ObjectId("60fefc1f535ed8596d08c151"),
ObjectId("6102e3c4535ed8596d3723da"),
ObjectId("612163ca535ed8596dd57732"),
]
}
}
},
{
"$project" :
{
"_id": 0,
"ui": 1,
"tc": {
"$literal": 1
}
}
},
{
"$unionWith": {
"coll": "replies",
"pipeline": [
{
"$match" :
{
"ci": {
"$in": [
ObjectId("60fefc1f535ed8596d08c151"),
ObjectId("6102e3c4535ed8596d3723da"),
ObjectId("612163ca535ed8596dd57732"),
]
},
}
},
{
"$project" :
{
"_id": 0,
"ui": 1,
"rc": {
"$literal": 1
}
}
},
]
}
},
{
"$group": {
"_id": "$ui",
"tc": {
"$sum": "$tc"
},
"rc": {
"$sum": "$rc"
}
}
},
{
"$sort": {
"rc": -1
}
},
{
"$limit": 100
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment