I have a collection of items that have these properties:
- string id
- string descriptiveName
- list fieldsValue
- list fieldsRelationValue
- list relations
The FieldsValue
list is composed of various object, all with the same structure:
- dynamic value
- string id
- string name
- string nameAsProperty
- string type
Every item in this collection has the same FieldValues
with the same properties except for the value property (It can also be the same, but it’s not necessary).
Using .NET MongoDB driver, I want a method to sort the items from the collection by the value of a specified field. I’m trying to make the method so it receives the Id of the FieldValue
, then looks at every FieldValue
with that ID in every item and then sort the items using the Value of said FieldValue
.
These are 2 items as an example:
{
"id": "6668916b0821a7c652cbd42a",
"descriptiveName": "Client Name 29",
"fieldsValue": [
{
"value": "Client 29",
"id": "666891690821a7c652cbd377",
"name": "Client Name",
"nameAsProperty": "client_name",
"type": "string"
},
{
"value": true,
"id": "666891690821a7c652cbd378",
"name": "Active",
"nameAsProperty": "active",
"type": "boolean"
},
{
"value": 1713045600,
"id": "666891690821a7c652cbd379",
"name": "Day of sale",
"nameAsProperty": "day_of_sale",
"type": "date"
},
{
"value": 87,
"id": "666891690821a7c652cbd37a",
"name": "Total",
"nameAsProperty": "total",
"type": "decimal"
},
{
"value": 0,
"id": "666891690821a7c652cbd37b",
"name": "Discount",
"nameAsProperty": "discount",
"type": "decimal"
}
],
"fieldsRelationValue": [],
"relations": []
},
{
"id": "6668916b0821a7c652cbd429",
"descriptiveName": "Client Name 28",
"fieldsValue": [
{
"value": "Client 28",
"id": "666891690821a7c652cbd377",
"name": "Client Name",
"nameAsProperty": "client_name",
"type": "string"
},
{
"value": false,
"id": "666891690821a7c652cbd378",
"name": "Active",
"nameAsProperty": "active",
"type": "boolean"
},
{
"value": 1713218400,
"id": "666891690821a7c652cbd379",
"name": "Day of sale",
"nameAsProperty": "day_of_sale",
"type": "date"
},
{
"value": 84,
"id": "666891690821a7c652cbd37a",
"name": "Total",
"nameAsProperty": "total",
"type": "decimal"
},
{
"value": 0,
"id": "666891690821a7c652cbd37b",
"name": "Discount",
"nameAsProperty": "discount",
"type": "decimal"
}
],
"fieldsRelationValue": [],
"relations": [
{
"relatedAppName": "Invoices Sample",
"relatedAppId": "6668916b0821a7c652cbd430",
"relatedItems": [
{
"relatedItemName": "Invoice 45 - Client Name 28",
"relatedItemId": "6668916e0821a7c652cbd511"
}
]
}
]
}
I’m very lost here, I’ve tried lots of different things I found here but nothing seems to work for me.
2