2017-09-15 5 views
0

Comment traduire cette requête mongo shell en java?

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

Répondre

0

Vous pouvez utiliser la variante Projections.elemMatch(String fieldName) pour la projection positionnelle.

Quelque chose comme

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())