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)?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With