Radoslav Toth
June 29, 2022

MongoDB 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 an 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 MyCollection.find({});
  // this is the same as: 
  // return await db.collection("MyCollection").find({});
}
async function run() {
  const docs = await Amenities.find({}).toArray();
  for (const doc of docs) {
    await 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 Locations.update({slug: oldSlug}, {
      "$set": { "oldSlug": oldSlug, "slug": newSlug }
    }),
    'Attractions': await Attractions.updateMany({locationsCache: oldSlug}, {
      "$set": { "locationsCache.$": newSlug }
    }),
  }

  console.log('Locations and Attractions were updated.')

  return result;
}

Variables available in the function's scope

You can use the following variables in your code:

  • db: the current MongoDB database connection
  • {CollectionName}: Every collection name is a variable pointing to that collection: db.collection("Amenities") === Amenities
  • 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.
  • console.log(), console.warn(), console.error() to show a customized console with messages you send.

History

NodeShell keeps track of all previous functions executed so you can return to any of them later. Once you have a long list of history, you may search for any function using a fulltext search.

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.

Read more

Mingo Development Update

We're currently in the middle of a big refactoring and code cleanup effort in Mingo. Our goal is to bring everything up to date, streamline the codebase, improve performance, and set the stage for faster development and new features in the future. Here's what's happening: All this work takes time, but we’re aiming to ship […]
Radoslav Toth

v1.14.1 Released

Mingo is back with a new release packed with 42 improvements, fixes and goodies.
Radoslav Toth

v1.13.5 released

We are regularly releasing new versions and did it again today. The latest release contains several UX improvements, fixes 4 reported bugfixes (thanks!) and 10+ unreported issues we found ourselves. Please keep reporting issues, we appreciate any feedback! Mingo should suggest the update automatically, or you can download it directly from our Download page.
Radoslav Toth

Using Mingo with FerretDB

Mingo is a suitable solution for a GUI for MongoDB and its open-source alternative, FerretDB. Since FerretDB is open source, developers can fully control and adapt it to suit specific needs. FerretDB with Mingo will offer you a visual representation of data and a user-friendly interaction, among other benefits. What is FerretDB FerretDB is the […]
Daniel Njeru

Taking Your Company to New Heights with MongoDB Charts in Mingo

Today we demystify how Mingo can ease your pain as a MongoDB user. Mingo has had positive reviews from all companies that have tried it out. Some users have loved it for its wide range of features that are not in other GUI tools, while others have remained loyal to us due to our favorable […]
Daniel Njeru

How to set up MongoDB charts in Mingo

MongoDB charts are used to create a visual representation of MongoDB data. With MongoDB charts, you can communicate insights clearly and concisely. The feature will be useful when analyzing trends, presenting information, or making data-driven decisions. Complex information is conveyed in a more accessible format. That way, you can focus on developing actionable plans. Mingo […]
Daniel Njeru

Demystifying Data Modeling in MongoDB: A Step-by-Step Approach

Data modeling is the process of defining how data is stored and the relationships that exist among different entities in your data. The organization of data inside a database is referred to as a schema. When developing your schema, put more thoughts on your application than your database. A good data model makes data management […]
Daniel Njeru

Indexing Strategies for High Performance in MongoDB

Indexes are unique data structures that store a small portion of the collection’s data in an ordered form that is easy to traverse and search efficiently. They point to the document identity and allow you to look up, access, and update data faster. In MongoDB, indexes are used to improve query performance. Indexes improve query […]
Daniel Njeru

Which companies are using MongoDB

Those who come bearing advice are rarely popular. Daedalus did not do his son Icarus any favors by warning him not to fly too close to the sun as his wax wings would melt, causing him to fall. Had Icarus not ignored his father’s advice, he would not have plummeted to his death. By all […]
Daniel Njeru

New version released: 1.13.1

Here's a short list of bug fixes and improvements in our latest release. It is definitely not complete, there are many minor goodies we didn't even mention here. Enjoy! Bug Fixes Enhancements We would like to thank all the contributors for their valuable feedback and bug reports. Your contributions help us make Mingo better. Please […]
Radoslav Toth
1 2 3

Download Mingo now

The best MongoDB GUI Admin. Intuitive • Fast • Secure
Download Now