0
このmongo shell queryをjavaに翻訳するには?
db.collection.find({"array.element": "value"}, {"array.$": 1, "_id": 0})
このmongo shell queryをjavaに翻訳するには?
db.collection.find({"array.element": "value"}, {"array.$": 1, "_id": 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(elemMatch("array"), excludeId())