PromucFlow_constructor/deploy/docker/utils/bin/mongo_shell_utils.js
Sumesh Pradhan 2b55ec50fb
fix: update mongo cmd in evalMongo to use mongosh (#20780)
The cmd util appsmithctl now used `mongosh` instead of the legacy
`mongo` shell.
2023-02-24 12:19:19 +05:30

29 lines
676 B
JavaScript

const utils = require('./utils');
const command_args = process.argv.slice(3);
async function exec() {
let errorCode = 0;
try {
await execMongoEval(command_args[0], process.env.APPSMITH_MONGODB_URI);
} catch (err) {
errorCode = 1;
console.error('Error evaluating the mongo query', err);
} finally {
process.exit(errorCode);
}
}
async function execMongoEval(queryExpression, appsmithMongoURI) {
queryExpression = queryExpression.trim();
if (command_args.includes('--pretty')) {
queryExpression += '.pretty()';
}
return await utils.execCommand(['mongosh', appsmithMongoURI, `--eval=${queryExpression}`]);
}
module.exports = {
exec
};