Skip to content

Instantly share code, notes, and snippets.

@MartinPavlik
Created November 14, 2020 16:28
Show Gist options
  • Save MartinPavlik/08ba21c84d7d594b325c7375cb03fc4a to your computer and use it in GitHub Desktop.
Save MartinPavlik/08ba21c84d7d594b325c7375cb03fc4a to your computer and use it in GitHub Desktop.
MongoDB median
db.getCollection('collection-name')
.find()
.sort( {"price":1} )
.skip(db.getCollection('collection-name').count() / 2 - 1)
.limit(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment