java API to retrieve max, min and unique values in MongoDB

1,027 views
Skip to first unread message

Shi Yu

unread,
Jan 12, 2011, 9:37:03 PM1/12/11
to mongod...@googlegroups.com
Hi,

What is the simplest Java API to retrieve the max, min and unique values in MongoDB collections? I was looking for something like the SQL "SELECT max( ) FROM" for the Servlet but didn't get any. It sounds as a very straightforward requirement and it should be done in a single line command. I did found some hints in the cookbook using Map/Reduce, but that seems requiring some coding, isn't it? Anyone has a quick example fining max, min and unique values using Map/Reduce (Java API at the servlet side)? Thanks.

Shi

Nat

unread,
Jan 12, 2011, 9:40:46 PM1/12/11
to mongodb-user
- for min, max, use sort and limit i.e.
sort({ score : 1}).limit(1) // for min
sort({ score : -1}).limit(1) // for max

- for unique value, use distinct or group (http://www.mongodb.org/
display/DOCS/Aggregation)

Shi Yu

unread,
Jan 12, 2011, 9:49:54 PM1/12/11
to mongod...@googlegroups.com
Ah! Thank you Nat!

Shi

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


   
 
       
 
 

CodeBeast

unread,
May 3, 2016, 3:29:12 AM5/3/16
to mongodb-user
Isn't it
sort({ score : 1}).limit(1) // for max
sort({ score : -1}).limit(1) // for min
???
Reply all
Reply to author
Forward
0 new messages