MCPcopy
hub / github.com/Pythagora-io/pythagora / prepareDB

Function prepareDB

src/helpers/mongodb.js:224–242  ·  view source on GitHub ↗
(pythagora, req)

Source from the content-addressed store, hash-verified

222}
223
224async function prepareDB(pythagora, req) {
225 await cleanupDb(pythagora);
226
227 const testReq = await pythagora.getRequestMockDataById(req);
228 if (!testReq) return;
229
230 let uniqueIds = [];
231 for (const data of testReq.intermediateData) {
232 if (data.type !== 'mongodb') continue;
233 let insertData = [];
234 for (let doc of data.preQueryRes) {
235 if (!uniqueIds.includes(doc._id)) {
236 uniqueIds.push(doc._id);
237 insertData.push(jsonObjToMongo(doc));
238 }
239 }
240 if (insertData.length) await pythagora.mongoClient.db(PYTHAGORA_DB).collection(data.collection).insertMany(insertData);
241 }
242}
243
244function extractDataFromMongoRes(mongoResult) {
245 // todo refactor to add path to mongoResult inside src/const/mongodb.js for each method

Callers 1

setUpExpressMiddlewaresFunction · 0.70

Calls 3

jsonObjToMongoFunction · 0.85
cleanupDbFunction · 0.70

Tested by

no test coverage detected