0

I want to backup certain documents in a MongoDB collection. These documents change from day to day in a Node.js/Mongoose app, and I want to be able to restore these documents (and only these documents) to any former state. Are there any best practices to backup and restore single documents?

I already came up with a simple approach to store the documents in a backup collection on a daily basis:

let backupData = new BackupData({
    title: document_title,
    timestamp: new Date(),
    data: document_data
})
backupData.save()

From this collection, I can load a previously stored document indicating its title and timestamp. Probably not the best solution. And I am also stuck at the point how to restore the document. Just saving it does not change the document in the database (no error thrown).

Onno
  • 821
  • 10
  • 20
  • have you checked this question? https://stackoverflow.com/questions/3507624/mongodb-nosql-keeping-document-change-history?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Igal Klebanov Apr 10 '18 at 13:29
  • Yes, thanks! The proposed solution is probably helpful for others. In my case, the document structure is too complicated to track changes per field. For a start I will stick to my approach. – Onno Apr 11 '18 at 08:43

0 Answers0