Try Studio 3T for Free
  1. Knowledge Base
  2. MongoDB Tutorials
  3. Getting Started with MongoDB
  4. 10+ Basic MongoDB Commands Translated to Clicks

10+ Basic MongoDB Commands Translated to Clicks

As you get started with MongoDB, it pays off to use tools that help you stay productive from the get-go.

Studio 3T is exactly such: it’s the professional GUI and IDE for MongoDB.

It will take some time to learn how to speed up your queries or master the aggregation framework (don’t worry, we’ve got plenty of MongoDB tutorials). But for now, here’s a list of frequently-used MongoDB commands you’ll surely come across, replaced by a few clicks in Studio 3T’s rich context menus.

Download Studio 3T and be productive from Day One, regardless of your MongoDB knowledge level.

Databases

MongoDB create database

There’s actually no command to do so – MongoDB automatically creates a database when a collection is created in it.

  1. In the Connection Tree, right-click on the target server.
  2. Choose Add Database.Right-click on the target server and choose Add Database
  3. Name your database – and note the info message.Name your newly created MongoDB database
  4. Click on OK.  Make sure to add a collection!

MongoDB command equivalent

use dbName

MongoDB drop database

Now, let’s drop (or delete) the newly created database, manatee.

  1. Right-click on the target database.
  2. Choose Drop Database.
    Right click on the target database and choose Drop database
  3. Click Drop Database.

MongoDB command equivalent

db.dropDatabase()

//drops the current database you're in

MongoDB show databases

No clicks needed here. You can view this information directly from the Connection Tree.

View the full list of databases directly from the Connection Tree

MongoDB command equivalent

db.adminCommand( { listDatabases: 1, nameOnly: true} )

// lists database names only

Collections

MongoDB show collections

In the Connection Tree:

  1. Click on your target database.
  2. Click on the Collections folder. This opens up the list of collections within that database.Click on the target database then the Collections folder to show all collections.

MongoDB command equivalent

db.getCollectionNames()

MongoDB create collection

  1. Right-click on your target database.
  2. Choose Add Collection.
    Right click on a database and choose Add Collection
  3. Enter a collection name and configure the settings as needed under the Options, Storage Engine, Validator, and Collation tabs.
    Enter a collection name and configure the right settings
  4. Click Create.

MongoDB command equivalent

db.createCollection("collectionName");

MongoDB clear collection

  1. Right-click on your target collection.
  2. Choose Clear Collection.Choose your target collection and click on Clear Collection
  3. Click on Clear Collection.

MongoDB command equivalent

db.users.deleteMany({})

MongoDB drop collection

  1. Right-click on a target collection.
  2. Choose Drop Collection.Right click on a target collection and choose Drop collection
  3. Click Drop Collection.

MongoDB command equivalent

db.collection_name.drop()

Documents

MongoDB insert document

  1. While in Table View or Tree View, right-click on any cell.
  2. Choose Insert Document. This opens the Insert Document > JSON window.
  3. Enter the key value pairs. There’s no need to create the _id field – MongoDB does this automatically.Insert JSON document to be added

    Click on Validate JSON to make sure the syntax is correct.

  4. Click on Add Document if adding one document, or Add & Continue if adding more documents.

MongoDB command equivalent

db.collectionName.insert({ field1: “value1”, field2: “value2” })

MongoDB update document

Studio 3T supports in-place editing, so all you need to do double-click on a value to edit it.

Double click to edit date in place.

Here’s the complete post on how MongoDB() update works in Studio 3T.

MongoDB command equivalent

db.collection.updateOne(<filter>, <update>, <options>)

MongoDB remove document

  1. Right-click on your target document.
  2. Choose Remove Document.Choose your target document and click Remove document
  3. Click on Remove Document again.

MongoDB command equivalent

db.collection.deleteOne()

To delete all documents from a collection, follow the instructions on how to clear a collection.

Fields

MongoDB add field

  1. Right-click on any cell while in Table View or Tree View.
  2. Go to Field > Add Field/Value.
  3. Enter a field name (e.g. favorite-color).
  4. Choose the right field type (e.g. String).
  5. Define the field value (e.g. green).
  6. Choose where to add the field to (e.g. Current document only).
  7. Click on Add Field/Value.Configure the settings of your new field as needed

MongoDB command equivalent

{ $set: { <field1>: <value1>, ... } }

MongoDB rename field

Let’s rename the field from favorite-color to color.

  1. Right-click any cell that contains the field you want to rename.
  2. Go to Field > Rename Field.
  3. Update the field name.
  4. Choose where the field name should be updated (e.g. All documents in collection).
  5. Click Rename.Rename a MongoDB field in your current document, all documents, or documents matching your query criteria

MongoDB remove field

Now, let’s remove the color field entirely.

  1. Right-click a cell with the field you want to delete.
  2. Choose to remove the field from the current document, documents matching a query, or all documents.Choose to remove a field from the current document, documents matching a query, or all documents
  3. Click Remove.

Want more MongoDB hacks?

Updated on July 26, 2019

Was this article helpful?

Related Articles

Leave a Comment