1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.Map;
 
import com.mongodb.*;
 
public class EnumerateFields {
	public static void main(String[] args) {
 
		try {
			Mongo mongo = new Mongo("localhost", 27017);
			DB db = mongo.getDB("yourdb");
 
			DBCollection collection = db.getCollection("yourcollection");
 
			DBObject dbObject = collection.findOne();
			Iterator itr = dbObject.toMap().keySet().iterator();
			while(itr.hasNext())
				System.out.println(itr.next());
 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (MongoException e) {
			e.printStackTrace();
		}
	}
}