Mingo Documentation

NodeShell

Mingo's NodeShell let's you execute JavaScript code to work with data directly in Mingo. 
This is NOT MONGO SHELL, though.

The command must be a regular async JS function with a return value.

This allows complex code with loops, conditions and variable initialization to be executed. This code must be a definition of a async function and should return something to see "results". You can use this to fetch and process data using JS code and return the result or update documents using a script with loop, etc. Examples:

async function run() {
  return await db.collection("").find({});
}
async function run() {
  const docs = await db.collection("Amenities").find({}).toArray();
  for (const doc of docs) {
    await db.collection("Amenities").updateOne({_id: doc._id}, {$set: {something: "new"}})
  }

  return docs.length;
}
async function run() {
  const oldSlug = await MingoPrompt('What was the old slug?')
  const newSlug = await MingoPrompt('What will be the new slug?')
  const confirmed = await MingoConfirm('You want to change ' + oldSlug + ' to ' + newSlug + '?');
  if (!confirmed) return false;

  const result = {
    'Locations': await db.collection("Locations").update({slug: oldSlug}, {
      "$set": { "oldSlug": oldSlug, "slug": newSlug }
    }),
    'Attractions': await db.collection("Attractions").updateMany({locationsCache: oldSlug}, {
      "$set": { "locationsCache.$": newSlug }
    }),
  }
  return result;
}

Variables available in the function's scope

You can use the following variables in your code:

  • db: the current MongoDB database connection
  • ObjectId: MongoDB wrapper for creating and manipulating ObjectIds
  • dayjs: for work with dates
  • _: lodash
  • MingoConfirm(message): Simple confirm modal shown with specified message. Returns true if user clicked on OK and false on Cancel.
  • MingoAlert(message): Simple alert modal shown with specified message. 
  • MingoPrompt(message): Simple prompt modal shown with specified message. Returns the value the user entered.

Snippets and saved code

Mingo provides some example snippets. You may also save your code for later use. Code is saved for each database separately. History of your executed commands is also available.