I am working with Mongo aggregation/filter/sorting and limit with JAVA.
I have below model objects. CustomPOJO is my database collection.
@Document(collation = "CustomPOJO")
public class CustomPOJO {
public List<KeyValueObject> valueList;
public String attribute1;
public String attribute2;
public CustomObject attribute3;
}
public class CustomObject {
public String attribute4;
public String attribute5;
}
public class KeyValueObject {
public String name;
public String value;
}
Now I have entries in my DB with below records
Record1:
{
"valueList": [{
"name": "field1",
"value": "value1"
}, {
"name": "field2",
"value": "value2"
}, {
"name": "field3",
"value": "value3"
}],
"attribute1": "attribute1",
"attribute2": "attribute2",
"attribute3": {
"attribute4": "attribute4",
"attribute5": "attribute5"
}
}
Record2:
{
"valueList": [{
"name": "field1",
"value": "value4"
}, {
"name": "field2",
"value": "value5"
}, {
"name": "field3",
"value": "value6"
}],
"attribute1": "attribute11",
"attribute2": "attribute22",
"attribute3": {
"attribute4": "attribute44",
"attribute5": "attribute55"
}
}
I am able to do sort on all fields using sort(DESC,"attribute1") or sort(DESC,"attribute3.attribute4") or sort(DESC,"attribute2"). But i am unable to sort on valueList. I want to do sort according to specific KeyValue entry inside of valueList.
For example record1 have valueList with entry field1 so all records in DB should sort according field1 and value inside it.
In general i want to sort on field inside of list attribute.
Any help will be highly appreciate.