如何使用Java驱动程序抑制mongodb中的列?
我想用Java实现以下mongo查询如何使用Java驱动程序抑制mongodb中的列?,java,mongodb,Java,Mongodb,我想用Java实现以下mongo查询 db.getCollection('document').find({ "$and": [ {"storeId":"1234"}, {"tranDate" : {"$gte":new Date("Sat,01 Oct 2016 00:00:00 GMT"), "$lte":new Date("Mon,31 Oct 2016 00:00:00 GMT")}} ] }, {"_id" : 0}) 我有以下java代码,但我不确定如
db.getCollection('document').find({ "$and": [
{"storeId":"1234"},
{"tranDate" : {"$gte":new Date("Sat,01 Oct 2016 00:00:00 GMT"),
"$lte":new Date("Mon,31 Oct 2016 00:00:00 GMT")}}
]
},
{"_id" : 0})
我有以下java代码,但我不确定如何添加抑制逻辑
List<Bson> conditions = new ArrayList<>();
conditions.add(eq("field1", "value1"));
conditions.add(eq("field2", "value2"));
Bson query = and(conditions);
FindIterable<Document> resultSet = db.getCollection("document").find(query);
List conditions=new ArrayList();
添加(等式(“字段1”、“值1”);
添加(等式(“字段2”、“值2”));
Bson query=和(条件);
FindTable resultSet=db.getCollection(“文档”).find(查询);
我需要在代码逻辑中添加{“\u id”:0}以抑制“\u id”字段。请告诉我如何才能做到这一点。您可以尝试类似的方法
import static com.mongodb.client.model.Projections.excludeId;
FindIterable<Document> resultSet = db.getCollection("document").find(query).projection(excludeId());
导入静态com.mongodb.client.model.Projections.excludeId;
FindTable resultSet=db.getCollection(“文档”).find(query).projection(excludeId());
排除其他字段
import static com.mongodb.client.model.Projections.fields;
FindIterable<Document> resultSet = db.getCollection("document").find(query).projection(
fields(exclude("fieldname", "fieldvalue")));
导入静态com.mongodb.client.model.Projections.fields;
FindTable resultSet=db.getCollection(“文档”).find(query).projection(
字段(不包括(“字段名”、“字段值”));
获取完整的预测列表