Skip to content

Instantly share code, notes, and snippets.

@olgakogan
Created December 31, 2014 09:26
Show Gist options
  • Save olgakogan/49596cba8d8177813970 to your computer and use it in GitHub Desktop.
Save olgakogan/49596cba8d8177813970 to your computer and use it in GitHub Desktop.
######### using python mongoengine
min_age = Customer.objects(zip_code = 687218).order_by("age").first().age
max_age = Customer.objects(zip_code = 687218).order_by("-age").first().age
######### using mongo client commands
#MIN
db.customers.find({"zip_code":683749}).sort( { age: 1 } ).limit(-1)
#MAX
db.customers.find().sort( { age: -1 } ).limit(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment