I'm new on MongoDB, on my project i'm saving any change on specific document creating a new document with changes and a version field increased.
Example:
{_id:"X", number : "1", firstname : "John", lastname : "Sand", version : "1"}
{_id:"Y", number : "1", firstname : "John", lastname : "Snow", version : "2"}
{_id:"Z", number : "2", firstname : "Cersei", lastname : "Lannister", version: "1"}
When I have to show data i should get the last version of document distincted by field "number"
the result expected is:
{_id:"Y", number : "1", firstname : "John", lastname : "Snow", version : "2"}
{_id:"Z", number : "2", firstname : "Cersei", lastname : "Lannister", version: "1"}
Is there a method to do this with one query? I'm looking for aggregation but the subject is very dispersive.