Created
November 14, 2020 16:28
-
-
Save MartinPavlik/08ba21c84d7d594b325c7375cb03fc4a to your computer and use it in GitHub Desktop.
MongoDB median
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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