Skip to content

Instantly share code, notes, and snippets.

@erh
Created September 14, 2010 22:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erh/579892 to your computer and use it in GitHub Desktop.
Save erh/579892 to your computer and use it in GitHub Desktop.
coll = db.foo
coll.drop()
coll.insert( { arr : [ { a : 1 } , { b : 2 } , { c : 3 } ] } )
coll.insert( { arr : [ { a : 2 } , { b : 3 } , { c : 1 } ] } )
coll.insert( { arr : [ { a : 3 } , { b : 1 } , { c : 2 } ] } )
coll.ensureIndex( { arr : -1 } )
coll.find().min( { arr : { a : 5000 } } ).max( { arr : { a : 1 } } ).forEach( printjson )
@jtoy
Copy link

jtoy commented Sep 15, 2010

is the find possible form the ruby driver at all? I read the source of the driver and was unable to see how its possible to run the fins with the min and max functions

@erh
Copy link
Author

erh commented Sep 15, 2010

Yes - its just using $min, $max under the hood.

@jtoy
Copy link

jtoy commented Sep 16, 2010

Is there anything else I can do regarding http://groups.google.com/group/mongodb-user/browse_thread/thread/578c6d037d241162 ? I am at a loss of how to get this working.

@erh
Copy link
Author

erh commented Sep 16, 2010

Looks like you didn't follow the example.
Notice the ensureIndex has a -1 rather than 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment