Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongodb

robo3t

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

like image 869
Shai Rippel Avatar asked Jul 05 '18 10:07

Shai Rippel


People also ask

How do you create index in MongoDB?

The indexes are ordered by the value of the field specified in the index. So, MongoDB provides a createIndex() method to create one or more indexes on collections. Using this method we can create different types of indexes like text index, 2dsphere index, 2d index, etc.

How do I create an index in Studio 3T?

In Studio 3T, connect to your MongoDB server. You'll then see the databases and their collections in the left-hand Collections pane. Simply right-click on the collection you want to create a new index for and choose “Add Index…” from the pop-up menu, as shown below. This will open the “Add Index” view.

How do I create a local MongoDB database in Robo 3T?

To create a new MongoDB database, right-click on the New Connection and select Create Database in the pop-up menu. The “Create Database” window will appear asking the user to enter the desired database name in the “Database Name” field.


1 Answers

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

like image 110
Shai Rippel Avatar answered Sep 20 '22 22:09

Shai Rippel