Is it possible a document in a collection to have a cycle? Not necessarily an update

Hi,

I would like to ask if possible a document in a collection to have a cycle or multiple version? Not necessarily an update, though technically it’s an update but in a sense that, the first version retain all the fields before the update, after the update, it will create a new version. This versions will store on the same document and it is accessible on the client.

Let say, in an insurance company, an enrollee claimed his insurance, so we will set the status of that enrollee as claimed. Then that particular enrollee renewed his enrollment, basically, this enrollee’s documents has his name, birthdate, age, beneficiary and dependent etc(cycle 1)… Upon his renewal(cycle 2), he added additional dependent which is not in his previous enrollment(cycle 1).

The normal approach is to add that dependent, basically this is updating the document but how do i retain all the fields in cycle 1 without the additional dependent on cycle 2? What I have in my mind is create a cycle counter (dropdown), wherein, if the user select cycle 1, it will display all the fields without the additional dependent and then if the user select cycle 2 it will display all the fields in cycle 1 with the new declared dependent. But the problem is i don’t know how to start or is it possible in mongodb to have this kind of functionality.

Basically, the document has two instances/versions or I don’t know how its called.

Enrollments - same document in Enrollments collection

Cycle 1

  • Name - Lee
  • Age - 30
  • Dependent 1 - Amy
  • Dependent 2 - [null]

Lee renewed his enrollment and add Dependent 2
Cycle 2

  • Name - Lee
  • Age - 30
  • Dependent 1 - Amy
  • Dependent 2 - Han

Dropdown >

  • Cycle 1
  • Cycle 2

User select Cycle 1, display all fields in Cycle 1 or vice versa.

Appreciate any help.

Thanks,

Marvin

Look at this package, maybe it will help.

2 Likes

Thanks a lot @none!

Great! This is exactly what i am looking for!

Cheers!

Marvin