Загрузка...

How to Create Indexes in MongoDB

MongoDB - Index

Definition

An Index in MongoDB is a special data structure that stores a small portion of a collection's data in an easy-to-traverse form. Indexes improve the speed of query operations by allowing MongoDB to quickly locate documents without scanning the entire collection.

Steps to Create an Index in MongoDB

1). Open the MongoDB Shell using mongosh.

2). Select the database using use database_name.

3). Check the existing documents using find().

4). Choose the field on which the index needs to be created.

5). Use the createIndex() method.

6). Specify the field name and sort order (1 for ascending, -1 for descending).

7). Execute the command.

8). Verify the created index using getIndexes().

Example
use studentdb

db.students.createIndex(
{
name: 1
}
)
View Existing Indexes
db.students.getIndexes()

Видео How to Create Indexes in MongoDB канала Fratello Innotech
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять