Skip to content

Indexes

Nikolas Bompetsis edited this page May 30, 2020 · 3 revisions

First connect to mongodb cli

> mongodb master ✗ mongo -u admin -p admin --authenticationDatabase admin

> use project

Create Single Field Indexes

In our collection named stackoverflow that holds documents, we want to create an index based on one field

> db.stackoverflow.createIndex( { "Country": 1 } )

Create Single Field Indexes

MongoDB supports compound indexes, where a single index structure holds references to multiple fields and can support queries that match on multiple fields.

> db.stackoverflow.createIndex( { "Country": 1, "Age": 1 } )
Clone this wiki locally