Skip to content

Instantly share code, notes, and snippets.

@ryanvgates
Created September 7, 2021 16:01
Show Gist options
  • Save ryanvgates/804b2fc9efd9e422fccbd22bf8855b3c to your computer and use it in GitHub Desktop.
Save ryanvgates/804b2fc9efd9e422fccbd22bf8855b3c to your computer and use it in GitHub Desktop.
MongoDB Long Running Query
use mydb;
rs.secondaryOk();
db.Collection.aggregate([
{
$match: {
groups: { $exists: true }
}
},
{
$group: {
_id: {
CustomerId: "$CustomerId",
},
groups: { $sum: { $size: "$Groups" } }
}
},
{
$match: {
"countGroups": { $gt: 0 }
}
}
]).toArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment