The mongo testmodel replay files and an hard coded instantiation hook assuming:
Property | Value (hard coded!) | |
---|---|---|
Mongo DB Connection string | 'mongodb://localhost/testdb2' |
|
data Folder | mgrecrep2/ |
|
Control environment varialbe | MGNLQ_TESTMODEL2_REPLAY |
Note: in default mode no mongo connection is established and REPLAY mode is on. (see mongoose_record_replay)
const Model = require('mgnlq_model');
require('mgnlq_testmodel2').getTestModel().then( theModel =>
{
// your code using theModel
Model.releaseModel(theModel);
}
);
var mongooseMock = require('mongoose_record_replay').instrumentMongoose(require('mongoose'),
'node_modules/mgnlq_testmodel2/mgrecrep/',
mode);
var aPromise = undefined;
function getModel() {
if(mode === 'REPLAY') {
// in replay mode during testing, using a singleton is sufficient
aPromise = aPromise || Model.loadModelsOpeningConnection(mongooseMock,'mongodb://localhost/testdb2' );
return aPromise;
}
// open a real connection, which has to be closed
return Model.loadModelsOpeningConnection(mongooseMock, 'mongodb://localhost/testdb');
}
environment variable
MGNLQ_TESTMODEL2_REPLAY
control the mode.
- REPLAY (default)
- RECORD
- OFF
Beware: the underlying model uses a caching mechanism, thus it attempts to write to folders.
Similar, in RECORD mode, mgrecrep/queries.json and mgrecrep/data may be extened with new files.
npm run create_db
todo
node js/scripts/migrate_raw.js
(copies to /tmp) requires manual postprocessing and merging