Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save JanPaulEttles/2227066 to your computer and use it in GitHub Desktop.
jandefence3
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> var count = 0;
> while(cursor.hasNext()) {
... count++;
... var current = cursor.next();
... print(max + ' ' + current.someNumber);
... if(current.someNumber> max) {
... print(max + ' ' + current.someNumber);
... max = current.someNumber;
... }
... }
-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 20
20 200
20 200
200 50
200 50
50 90
50 90
90
> print(max);
90
> print(count);
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment