}
public synchronized BSONObject handleDistinct(BSONObject query) throws MongoServerException {
String key = query.get("key").toString();
BSONObject q = (BSONObject) query.get("query");
TreeSet<Object> values = new TreeSet<Object>(new ValueComparator());
for (Integer pos : queryDocuments(q)) {
BSONObject document = documents.get(pos.intValue());
if (document.containsField(key))
values.add(document.get(key));