Skip to content

Instantly share code, notes, and snippets.

@dzhuryn
Last active June 10, 2023 07:52
Show Gist options
  • Save dzhuryn/52b0c44e3789c52b31f92358661336f6 to your computer and use it in GitHub Desktop.
Save dzhuryn/52b0c44e3789c52b31f92358661336f6 to your computer and use it in GitHub Desktop.
db.threads.aggregate([
{
"$match": {
"$text": {
"$search": "modx"
}
}
},
{
"$facet":{
"count": [
{
"$group": {_id: null, count: {$sum: 1}}
}
],
"channelIDs": [
{
"$group": {_id: "$ci"}
}
]
}
}
])
Result is:
{
"count" : [
{
"_id" : null,
"count" : 360.0
}
],
"channelIDs" : [
{
"_id" : ObjectId("60fdb9d0535ed8596df08b90")
}
]
}
Can i have result in form
{
"count" : 360.0,
"channelIDs" : [
ObjectId("60fdb9d0535ed8596df08b90"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment