...

Database Managment - Mongo DB

Back to Course

Lesson Description


Lession - #1424 MongoDB Indexing


MongoDB - Indexing

Indexes support the effective goal of questions. Without files, MongoDB should filter each report of an assortment to choose those records that match the inquiry articulation. This sweep is profoundly wasteful and require MongoDB to handle a huge volume of information.
Indexes are unique information structures, that store a little piece of the informational index in a simple to-navigate structure. The file stores the worth of a particular field or set of fields, requested by the worth of the field as indicated in the list.

The createIndex(>
Method

To make a index, you want to utilize createIndex(>
strategy for MongoDB.
Syntax The basic syntax of createIndex(>
method is as follows(>
.

>db.COLLECTION_NAME.createIndex({KEY:1}>
Here key is the name of the field on which you need to make list and 1 is for rising request. To make record in dropping request you really want to utilize - 1.
Example

>db.mycol.createIndex({"title":1}>
{ "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } >

In createIndex(>
method you can pass multiple fields, to create index on multiple fields.

>db.mycol.createIndex({"title":1,"description":-1}>
>
The createIndex(>
strategy likewise has various discretionary boundaries. These include:
  • background (Boolean>
  • unique (Boolean>
  • name (string>
  • sparse (Boolean>
  • Drop an Index

In order to drop an index, MongoDB provides the dropIndex(>
method. Syntax –

db.NAME_OF_COLLECTION.dropIndex({KEY:1}>
The dropIndex(>
strategies can erase each file in turn. To erase (or drop>
various files from the assortment, MongoDB gives the dropIndexes(>
strategy that accepts numerous records as its boundaries.
Syntax –

db.NAME_OF_COLLECTION.dropIndexes({KEY1:1, KEY2, 1}>
The dropIndex(>
techniques can erase each record in turn. To erase (or drop>
various files from the assortment, MongoDB gives the dropIndexes(>
strategy that accepts numerous records as its boundaries.

Get description of all indexes :

The getIndexes(>
technique in MongoDB gives a depiction of the multitude of records that exists in the given assortment.
Syntax –
db.NAME_OF_COLLECTION.getIndexes(>