2017-09-15 7 views
0

このmongo shell queryをjavaに翻訳するには?

db.collection.find({"array.element": "value"}, {"array.$": 1, "_id": 0}) 

答えて

0

位置投影にはProjections.elemMatch(String fieldName)バリアントを使用できます。

何か

よう
import static com.mongodb.client.model.Filters.eq; 
import static com.mongodb.client.model.Projections.elemMatch; 
import static com.mongodb.client.model.Projections.excludeId; 
import static com.mongodb.client.model.Projections.fields; 

List<Document> results = collection.find(eq("array.element", "value")).projection(fields(elemMatc‌​h("array"), excludeId())