mongoid-history icon indicating copy to clipboard operation
mongoid-history copied to clipboard

How to get what the collection looked like on a version?

Open jalaj-hn opened this issue 2 years ago • 3 comments

My collection's version is 22 for example and I want to know what it looked like at version 5. Is there a inbuilt way to do that?

jalaj-hn avatar Feb 12 '24 10:02 jalaj-hn

Tracks let you get the original and the modified version.

track = post.history_tracks.first
track.original # {}
track.modified # { "title" => "Test", "body" => "Post", "comments" => [{ "_id" => "575fa9e667d827e5ed00000d", "title" => "test", "body" => "comment" }], ... }

I think it'd be great to add a helper [] method to find one at a specific version, I'd like something like post.history_tracks[22], post.history_tracks.versions[22], or post.history_tracks.find(22) to work. Want to give it a shot?

dblock avatar Feb 12 '24 14:02 dblock

Tracks let you get the original and the modified version.

Thanks. This will give me the original value of changed fields. So to get the whole collection with all its fields, I'll need to loop over the tracks and form the collection, right?

I like the helper method suggestion, I'll try to find some time on weekend and work on it.

jalaj-hn avatar Feb 13 '24 03:02 jalaj-hn

Thanks. This will give me the original value of changed fields. So to get the whole collection with all its fields, I'll need to loop over the tracks and form the collection, right?

Are you trying to find a state for multiple records? I think some helper methods for that, even if inefficient, could be awesome, e.g. Post.all.at(timestamp), etc.

dblock avatar Feb 13 '24 04:02 dblock