Skip to content

Instantly share code, notes, and snippets.

@claustres
Last active August 28, 2017 12:52
Show Gist options
  • Save claustres/b3b645b7c9e55da374e339af1eb4581c to your computer and use it in GitHub Desktop.
Save claustres/b3b645b7c9e55da374e339af1eb4581c to your computer and use it in GitHub Desktop.
Query MongoDB collection
db = db.getSiblingDB('random');
var start = new Date();
printjson(db.randomData.aggregate([ { $group : { _id: null, max: { $max : "$value" }}} ], {allowDiskUse: true}).toArray());
print('Find maximum value in ' + (new Date() - start)/1000.0 + 's');
start = new Date();
printjson(db.randomData.find( { value: { $gt: 99.9 } } ).sort({ value: -1}).limit(100).toArray());
print('Find values > 99.9 in ' + (new Date() - start)/1000.0 + 's');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment