Я использую этот драйвер
Код: Выделить всё
org.mongodb
mongo-java-driver
3.4.2
Код: Выделить всё
db.getCollection('COLLECTION').aggregate(
[
{"$match": {"val.elem.0001": {"$exists":true}}},
{"$project": {"FIELD_PATH": "$val.elem.0001"}},
{$group: {_id:{"FIELD": {"$literal": "0001"}},
"PATH": {"$addToSet": "$FIELD_PATH"}}}
]
);
Код: Выделить всё
AggregateIterable output = collection.aggregate(Arrays.asList(
new Document("$match", new Document("val.elem.0001",new Document("$exists",true))),
new Document("$project", new Document("FIELD_PATH","$val.elem.0001")),
new Document("$group", new Document("_id",new Document("FIELD", new Document("$literal", "0001"))
.append("PATH", Accumulators.addToSet("$PATH", "$FIELD_PATH"))))));
Код: Выделить всё
Can't find a codec for class com.mongodb.client.model.BsonFieldИтак, чтобы подвести итог и сделать более читабельным и полным то, что я спросил:
- Правильно ли представление запроса в Java?
- Если да, то почему я не могу распечатать или получить доступ к результату запроса?
Подробнее здесь: https://stackoverflow.com/questions/449 ... er-in-java