I am trying to export report data from the mongoDB store into a .jsrexport file as soon as the instance is initialized.
const dotenv = require('dotenv');
const jsrCore = require('@jsreport/jsreport-core');
dotenv.config();
let config = require('./jsreport.config.json');
config.extensions['mongodb-store'].uri = process.env.DB_URI;
const jsreport = jsrCore(config);
async function exportData() {
try {
const reportData = await jsreport.export({
all: true,
output: 'export.jsrexport',
});
console.log('Data exported successfully.', reportData);
} catch (err) {
console.error('Failed to export data:', err);
}
}
if (process.env.JSREPORT_CLI) {
module.exports = jsreport;
} else {
jsreport
.init()
.then(async () => {
console.log('Report Server Started...');
await exportData();
})
.catch((err) => {
console.error('Failed to start Report Server...', err);
process.exit(1);
});
}
This is throwing the error "Failed to export data: TypeError: Cannot read properties of undefined (reading 'context'), I need a way to export existing MongoDB form data and programmatically import the exported file somewhere else.