UNPKG

@joktec/mongo

Version:

JokTec - Mongo Service

28 lines 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mongoDebug = void 0; const mongoDebug = (collectionName, methodName, ...methodArgs) => { const args = methodArgs .map(arg => { if (typeof arg === 'object') { return JSON.stringify(arg).replace(/"/g, ''); } return arg; }) .join(', '); let mongoShell = `db.${collectionName}.${methodName}(${args})`; if (methodName === 'find' || methodName === 'findOne') { const projection = methodArgs[1] || {}; const options = methodArgs[2] || {}; mongoShell = `db.${collectionName}.${methodName}(${args}).projection(${JSON.stringify(projection)})`; if (options.sort) mongoShell += `.sort(${JSON.stringify(options.sort)})`; if (options.skip) mongoShell += `.skip(${options.skip})`; if (options.limit) mongoShell += `.limit(${options.limit})`; } return mongoShell; }; exports.mongoDebug = mongoDebug; //# sourceMappingURL=mongo.utils.js.map