Filter array in Morphia

114 views Asked by At

I have an entity "PlayerStatisticsData" that has a field "transactions" containing another object "PlayerTransaction", which has a timestamp field.
However, since that list can get really big, I only want to query recent objects.
How can I query PlayerStatisticsData, but with a transactions list that only contains PlayerTransaction objects which's timestamp are greater than a given value?

I hope this was clear to understand.

enter image description here

1

There are 1 answers

0
evanchooly On

You can use a project to define an array slice but that only lets you specify how many to return. You can't introspect the values and filter out items like that. So, e.g., you could ask mongo to return the first or last 50 (if they're already ordered) but you can't tell it to slice by, say, a date field on the array element's document.

https://www.mongodb.com/docs/manual/reference/operator/projection/slice/