PromucFlow_constructor/deploy/docker/utils/bin/mongo_shell_utils.js
Sumesh Pradhan a1be1bf941
feat: appsmithctl version and mongo-eval utils (#19075)
`appsmithctl version` - Util to display current Appsmith version
`appsmithctl mongo-eval '<mongo query>' [--pretty]` - Util to run mongo
queries

Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
2023-01-03 12:14:21 +05:30

29 lines
674 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(['mongo', appsmithMongoURI, `--eval=${queryExpression}`]);
}
module.exports = {
exec
};