I want to retrieve only ID column with value less than 4,
MongoDatabase database = client.getDatabase("d");
MongoCollection<org.bson.Document> contCol = database.getCollection("test");
BasicDBObject query = new BasicDBObject();
query.put("ID",1);
FindIterable<org.bson.Document> it = contCol.find().projection(excludeId());
Doesn't give me the required output. The collection test has two columns, namely ID and name ; the query is returning both the columns, I want to get only the ID column.
To specify which columns you want included, you need to specify that in your projection; for example using the include() method .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.