@Test
//https://groups.google.com/forum/?fromgroups#!topic/jongo-user/Nu4J1tK0kAM
public void canSelectOnlyAField() throws Exception {
final Unmarshaller unmarshaller = getMapper().getUnmarshaller();
Party party = new Party();
party.with(new Friend("John"));
party.with(new Friend("Peter"));
party.with(new Friend("Robert"));
collection.save(party);
Friend friend = collection.findOne("{friends.name:'Peter'}").projection("{friends.$:1}").map(new ResultHandler<Friend>() {
public Friend map(DBObject dbo) {
Party result = unmarshaller.unmarshall((BsonDocument) dbo, Party.class);
return result.friends.get(0);
}
});
assertThat(friend.getName()).isEqualTo("Peter");