Removing MongoDB data for selective time periods or objects

If you wish to remove MongoDB data for selected periods of time or only remove data for certain objects, then Lua functions in the “inmation.MongoOps” library can be used. To remove all archived data between certain timepoints the HIST_REMOVETIMESPANALL() function can be used. This function has the following arguments:

  • tstart - The start time for the selected time period (in ISO 8601 format)

  • tend – The end time for the selected time period (in ISO 8601 format)

  • use_test_archive – An optional flag to export test archive data

Example:

local mongoops = require('syslib.MongoOps')

local ok, err = pcall(
    mongoops.HIST_REMOVETIMESPANALL,
    mongoops,
    "2017-01-01T12:00:00.000Z",
    "2019-01-01T12:00:00.000Z"
    )
return string.format("%s : %s", ok, err)

If you wish to export data from test archives then:

local mongoops = require('syslib.MongoOps')

local ok, err = pcall(
    mongoops.HIST_REMOVETIMESPANALL,
    mongoops,
    "2017-01-01T12:00:00.000Z",
    "2019-01-01T12:00:00.000Z",
    true
    )
return string.format("%s : %s", ok, err)

To only remove MongoDB data for selected objects, use the HIST_REMOVETIMESPAN() function. This function has the following arguments:

  • tstart – The start time for the selected time period (in ISO 8601 format)

  • tend – The end time for the selected time period (in ISO 8601 format)

  • obj_table – A Lua table containing the paths of all the objects whose archived data is to be exported

  • use_test_archive – An optional flag to export test archive data.

Example:

local mongoops = require('syslib.MongoOps')

local pathtable = {
    "/System/Core/Examples/DemoData/ProcessData/DC4711",
    "/System/Core/Examples/DemoData/ProcessData/DC666"
    }
local ok, docnumber = pcall(
    mongoops.HIST_REMOVETIMESPAN,
    mongoops,
    "2017-01-01T00:00:00.000Z",
    "2019-01-01T12:00:00.000Z",
    pathtable
    )
return string.format("%s : %s", ok, docnumber)

If you wish to export data from test archives then:

local mongoops = require('syslib.MongoOps')

local pathtable = {
    "/System/Core/Examples/DemoData/ProcessData/DC4711",
    "/System/Core/Examples/DemoData/ProcessData/DC666"
    }
local ok, docnumber = pcall(
    mongoops.HIST_REMOVETIMESPAN,
    mongoops,
    "2017-01-01T00:00:00.000Z",
    "2019-01-01T12:00:00.000Z",
    pathtable,
    true
    )
return string.format("%s : %s", ok, docnumber)