Skip to content

Instantly share code, notes, and snippets.

@gupta-shrinath
Created March 13, 2022 18:09
Show Gist options
  • Save gupta-shrinath/300e3a3802925e0d1afce560e7e6acc1 to your computer and use it in GitHub Desktop.
Save gupta-shrinath/300e3a3802925e0d1afce560e7e6acc1 to your computer and use it in GitHub Desktop.
pipeline = [
{
'$lookup': {
'from': 'students',
'as': 'studentArray',
'pipeline': [
{
'$sort': {
'balance_coins': -1
}
}, {
'$limit': 10
}
]
},
},
{
'$project': {
'balance_coins': 1,
'studentArray': {
'$filter': {
'input': '$studentArray',
'as': 'student',
'cond': {
'$eq': [
'$$student.branch', 'IT'
]
}
}
}
}
}
]
try:
results = db.students_coins_balance.aggregate(pipeline)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment