Updated on 2024-08-29 GMT+08:00

Creating an Index

Indexes can greatly improve query efficiency. If there are no indexes, each file in the collection must be scanned and the records that meet the query conditions must be selected when data is read. If the amount of data is large, querying an entire collection may take dozens of seconds or even minutes.

Procedure

  1. Log in to the DAS console.
  2. Click in the upper left corner and select a region and project.
  3. Click in the upper left corner, and under Databases, click Data Admin Service.
  4. In the navigation pane on the left, choose Development Tool.

    You can also click Go to Development Tool on the overview page.

  5. Locate the DB instance that you want to log in to and click Log In in the Operation column.
  6. On the top menu bar, choose Database Management.
  7. On the displayed page, click before the collection name.

    Figure 1 Expanding the collection list button

  8. Click New Index.

    Figure 2 Creating an index

  9. On the displayed page, configure basic parameters.

    Figure 3 Specifying index information
    Table 1 Parameter description

    Parameter

    Description

    Database

    Selected database by default. You can also enter a database name. After the index is created, the system automatically creates a database with the name you entered.

    Collection

    Selected collection by default. You can also enter a collection name. After the index is created, the system automatically creates a collection with the name you entered.

    Index

    Index name, which is user-defined.

    Advanced Settings

    • Background: indicates the backend mode for creating indexes.

      Selecting Background is recommended. If this option is not selected, the database will be locked.

    • Unique: specifies whether the created index is unique.
    • Sparse: does not enable indexes for field data that does not exist in the document.

    Index

    Click Add and enter a name and type to add an index.

  10. (Optional) on the Text Option page, select information such as the index version and default language.
  11. (Optional) on the Collation page, set the sorting rule.
  12. After the configurations are complete, click Save.