Is there a way to version control documents like git? I want to be able to let users update a document, while allowing them to use previous versions if needed.
Hi Alexander_Lau,
Daniel Coupal, one of our curriculum engineers, created a blog post that discusses this very problem. Please see: Building with Patterns: The Document Versioning Pattern | MongoDB Blog
The Document Versioning Pattern is just one option among many. A free MongoDB University course is available that dives much more into all the patterns if you’re interested:
Justin
Is there any implementation of this in C#?
Document versioning in MongoDB can be implemented in multiple ways, each with its pros and cons. Here are a few options:
- Embed version in the Document: Store a version field in each document and increment it with each update.
- Store each version as a separate document: Store each version of the document as a separate document in the collection, with a unique version identifier.
- Use MongoDB’s built-in change streams: MongoDB 4.0 and later support change streams, which can be used to track changes to a collection in real-time.
- Use a separate collection for version history: Store the version history of a document in a separate collection, which can be linked to the original document using a reference.
Whichever method you choose, make sure to test it thoroughly and to consider the trade-off between the complexity of the solution and the requirements for versioning in your use case.
For document versioning for Mongo db with Java , is there any collection or feature similar to ‘historical Collection’ module which is available for Python like historical-collection · PyPI ?