Skip to content

Instantly share code, notes, and snippets.

@JanPaulEttles
Created March 28, 2012 15:14
Show Gist options
  • Select an option

  • Save JanPaulEttles/2227085 to your computer and use it in GitHub Desktop.

Select an option

Save JanPaulEttles/2227085 to your computer and use it in GitHub Desktop.
jandefence4
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> while(cursor.hasNext()) {
... var current = parseInt(cursor.next().someNumber);
... print(max + ' ' + current);
... if(current > max) {
... print(max + ' ' + current);
... max = current;
... }
... }
-1 1
-1 1
1 10
1 10
10 100
10 100
100 110
100 110
110 120
110 120
120 150
120 150
150 20
150 200
150 200
200 50
200 90
> print(max);
200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment