final DBCursor cursor = collection.find().limit(1000);
final SortedMap<String, Set<Class<?>>> columnsAndTypes = new TreeMap<String, Set<Class<?>>>();
while (cursor.hasNext()) {
DBObject object = cursor.next();
Set<String> keysInObject = object.keySet();
for (String key : keysInObject) {
Set<Class<?>> types = columnsAndTypes.get(key);
if (types == null) {
types = new HashSet<Class<?>>();
columnsAndTypes.put(key, types);