How to create a Mongodb index in Robo 3T (formerly Robomongo)?

Shai Rippel picture Shai Rippel · Jul 5, 2018 · Viewed 10.6k times · Source

How can I use the Robo 3T GUI to create a simple index for one of the fields in a collection?

When I click on my collection, right click on the indexes folder and choose "add Index..." I see the next screen, what should I enter in the fields (mainly in the "Keys" field)?

Robo 3T Index Properties screenShot

Answer

Shai Rippel picture Shai Rippel · Jul 5, 2018

After some research and trial and error I found this is similar to the cli function db.collection.createIndex(keys, options)

About the Keys field: From the MongoDB documentation -

A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1

Let's say our field to index name is "accountNumber", you can enter this to the "Keys" black box pictured above:

{
      "accountNumber" : 1
}

For the Name just enter something meaningfull like accountNumberIndex

*The "Unique" checkbox will only work if there aren't already duplicate entries

*Also the Drop Duplicates is deprecated in Mongo version 3