MongoDB/NoSQL: Keeping Document Change History

后端 未结 5 1818
余生分开走
余生分开走 2020-12-02 03:31

A fairly common requirement in database applications is to track changes to one or more specific entities in a database. I\'ve heard this called row versioning, a log table

5条回答
  •  清歌不尽
    2020-12-02 04:07

    One can have a current NoSQL database and a historical NoSQL database. There will be a an nightly ETL ran everyday. This ETL will record every value with a timestamp, so instead of values it will always be tuples (versioned fields). It will only record a new value if there was a change made on the current value, saving space in the process. For example, this historical NoSQL database json file can look like so:

    {
      _id: "4c6b9456f61f000000007ba6"
      title: [
        { date: 20160101, value: "Hello world" },
        { date: 20160202, value: "Foo" }
      ],
      body: [
        { date: 20160101, value: "Is this thing on?" },
        { date: 20160102, value: "What should I write?" },
        { date: 20160202, value: "This is the new body" }
      ],
      tags: [
        { date: 20160101, value: [ "test", "trivial" ] },
        { date: 20160102, value: [ "foo", "test" ] }
      ],
      comments: [
        {
          author: "joe", // Unversioned field
          body: [
            { date: 20160301, value: "Something cool" }
          ]
        },
        {
          author: "xxx",
          body: [
            { date: 20160101, value: "Spam" },
            { date: 20160102, deleted: true }
          ]
        },
        {
          author: "jim",
          body: [
            { date: 20160101, value: "Not bad" },
            { date: 20160102, value: "Not bad at all" }
          ]
        }
      ]
    }
    

提交回复
热议问题