diff --git a/resources/views/query_runner.html b/resources/views/query_runner.html
index 746eb3d..093bf2f 100644
--- a/resources/views/query_runner.html
+++ b/resources/views/query_runner.html
@@ -44,9 +44,9 @@
-
+
-
Tablas
+
-
+
@@ -226,6 +232,16 @@ document.addEventListener('alpine:init', () => {
testMsg: '',
testOk: true,
toast: { show: false, msg: '', type: 'ok' },
+ isMongo: false,
+ mongoExamples: [
+ { label: 'find()', cmd: 'db.coleccion.find({})' },
+ { label: 'findOne()', cmd: 'db.coleccion.findOne({})' },
+ { label: 'count()', cmd: 'db.coleccion.countDocuments({})' },
+ { label: 'insertOne()', cmd: 'db.coleccion.insertOne({"campo": "valor"})' },
+ { label: 'updateOne()', cmd: 'db.coleccion.updateOne({"_id": ""}, {"$set": {"campo": "valor"}})' },
+ { label: 'deleteOne()', cmd: 'db.coleccion.deleteOne({"_id": ""})' },
+ { label: 'aggregate()', cmd: 'db.coleccion.aggregate([{"$group": {"_id": "$campo", "total": {"$sum": 1}}}])' },
+ ],
async init() {
// Pre-cargar ID desde URL si viene de conx_db
@@ -249,7 +265,10 @@ document.addEventListener('alpine:init', () => {
this.columns = [];
this.statusMsg = '';
this.history = [];
+ this.isMongo = false;
if (!this.selectedConxId) return;
+ const conx = this.conexiones.find(c => c.ID == this.selectedConxId);
+ this.isMongo = conx?.tipo_db?.nombre?.toLowerCase().includes('mongo') ?? false;
try {
const res = await axios.get('/app/query-runner/databases?conx_db_id=' + this.selectedConxId);
this.databases = res.data.data || [];
@@ -359,9 +378,10 @@ document.addEventListener('alpine:init', () => {
},
insertTable(name) {
- const sel = `SELECT * FROM ${name} LIMIT 100;`;
- this.sqlText = this.sqlText ? this.sqlText + '\n' + sel : sel;
+ const sel = this.isMongo ? `db.${name}.find({})` : `SELECT * FROM ${name} LIMIT 100;`;
+ this.sqlText = sel;
document.getElementById('sql-editor')?.focus();
+ this.runQuery();
},
clearEditor() { this.sqlText = ''; this.results = []; this.columns = []; this.statusMsg = ''; },