I’m trying to retrieve only a subset of fields from mongodb using Java driver. In documentation I found a way to do this javascript-way
db.posts.find( { tags : 'tennis' }, { comments : 0 } );
Trouble is, if I do similar thing in java
db.getCollection("posts").find(new BasicDBObject("comments",0));
What it does, is filtering objects where "comments" == 0, and does pull comments field as usual.
How to do this properly in java?
I think you have to use it the following way: