Create Indexes In Mongo

Introduction:

A provision to create indexes in MongoDB is made to enhance the performance of the Mongo DB.

Mongo Command- db.collection.createIndex()

The db.collection.createIndex() method is used to build an index on a collection.

The syntax for this command is as follows: db.collection.createIndex(keys, options)

Script Details:

db.categoryentity.createIndex({DisplayOrder: 1, ZnodeCategoryId: 1, ZnodeCatalogId: 1 , LocaleId: 1, VersionId: 1 , IsActive: 1})

Category Entity

  1. Indexes needed
    1. DisplayOrder
    2. ZnodeCategoryId
    3. ZnodeCatalogId
    4. LocaleId
    5. VersionId
    6. IsActive
  2. Order By
    1. DisplayOrder

Our Recommendation of queries to create the indexes:-

db.getCollection("categoryentity").createIndex( { "DisplayOrder": 1 } )

db.getCollection("categoryentity").createIndex( { "ZnodeCategoryId": 1 } )

db.getCollection("categoryentity").createIndex( { "ZnodeCatalogId": 1 } )

db.getCollection("categoryentity").createIndex( { "LocaleId": 1 } )

db.getCollection("categoryentity").createIndex( { "VersionId": 1 } )

db.getCollection("categoryentity").createIndex( { "IsActive": 1 } )

  1. db.logmessageentity.createIndex({CreatedDate: 1})

LogMessageEntity

  1. Indexes needed
    1. CreatedDate
  1. Order By
    1. CreatedDate

Our Recommendation of queries to create the indexes:-

db.getCollection("logmessageentity").createIndex( { "CreatedDate": 1 } )

db.versionentity.createIndex({ ZnodeCatalogId: 1, RevisionType: 1, LocaleId: 1})

VersionEntity

  1. Indexes needed
    1. ZnodeCatalogId
    2. RevisionType
    3. LocaleId

Our Recommendation of queries to create the indexes:-

db.getCollection("versionentity").createIndex( { "ZnodeCatalogId": 1 } )

db.getCollection("versionentity").createIndex( { "RevisionType": 1 } )

db.getCollection("versionentity").createIndex( { "LocaleId": 1 } )

db.configurableproductentity.createIndex({ZnodeProductId: 1, VersionId: 1})

ConfigurableProductEntity

  1. Indexes needed
    1. ZnodeProductId
    2. VersionId

Our Recommendation of queries to create the indexes:-

db.getCollection("configurableproductentity").createIndex( { "ZnodeProductId": 1 } )

db.getCollection("configurableproductentity").createIndex( { "VersionId": 1 } )

db.seoentitiy.createIndex({PortalId: 1, SEOTypeName: 1, LocaleId: 1 , VersionId: 1, SEOCode: 1})

SEOEntity

  1. Indexes needed
    1. PortalId
    2. SEOTypeName
    3. LocaleId
    4. VersionId
    5. SEOCode

Our Recommendation of queries to create the indexes:-

db.getCollection("seoentity").createIndex( { "PortalId": 1 } )

db.getCollection("seoentity").createIndex( { "SEOTypeName": 1 } )

db.getCollection("seoentity").createIndex( { "LocaleId": 1 } )

db.getCollection("seoentity").createIndex( { "VersionId": 1 } )

db.getCollection("seoentity").createIndex( { "SEOCode": 1 } )

db.addonentity.createIndex({DisplayOrder: 1, ZnodeProductId: 1, LocaleId: 1 , VersionId: 1, RequiredType: 1})

AddonEntity

  1. Indexes needed
    1. DisplayOrder
    2. ZnodeProductId
    3. LocaleId
    4. VersionId
    5. RequiredType
  2. Order By
    1. DisplayOrder

Our Recommendation of queries to create the indexes:-

db.getCollection("addonentity").createIndex( { "DisplayOrder": 1 } )

db.getCollection("addonentity").createIndex( { "ZnodeProductId": 1 } )

db.getCollection("addonentity").createIndex( { "LocaleId": 1 } )

db.getCollection("addonentity").createIndex( { "VersionId": 1 } )

db.getCollection("addonentity").createIndex( { "RequiredType": 1 } )

db.productentity.createIndex({ZnodeProductId: 1, SKULower: 1, ZnodeCatalogId: 1 , ZnodeCategoryIds: 1, LocaleId: 1, IsActive: 1 , VersionId: 1, ProductIndex: 1})

ProductEntity

  1. Indexes needed
    1. ZnodeProductId
    2. SKULower
    3. ZnodeCatalogId
    4. ZnodeCategoryIds
    5. LocaleId
    6. IsActive
    7. VersionId
    8. ProductIndex

Our Recommendation of queries to create the indexes:-

db.getCollection("productentity").createIndex( { "ZnodeProductId": 1 } )

db.getCollection("productentity").createIndex( { "SKULower": 1 } )

db.getCollection("productentity").createIndex( { "ZnodeCatalogId": 1 } )

db.getCollection("productentity").createIndex( { "ZnodeCategoryIds": 1 } )

db.getCollection("productentity").createIndex( { "LocaleId": 1 } )

db.getCollection("productentity").createIndex( { "ProductIndex": 1 } )

db.getCollection("productentity").createIndex( { "IsActive": 1 } )

db.getCollection("productentity").createIndex( { "VersionId": 1 } )

db.contentpageconfigentity.createIndex({PortalId: 1, IsActive: 1, ProfileId: 1 , VersionId: 1})

ContentPageConfigEntity

  1. Indexes needed
    1. PortalId
    2. IsActive
    3. ProfileId
    4. VersionId

Our Recommendation of queries to create the indexes:-

db.getCollection("contentpageconfigentity").createIndex( { "PortalId": 1 } )

db.getCollection("contentpageconfigentity").createIndex( { "IsActive": 1 } )

db.getCollection("contentpageconfigentity").createIndex( { "ProfileId": 1 } )

db.getCollection("contentpageconfigentity").createIndex( { "VersionId": 1 } )

db.textwidgetentity.createIndex({LocaleId: 1, PortalId: 1, VersionId: 1})

TextWidgetEntity

  1. Indexes needed
    1. LocaleId
    2. PortalId
    3. VersionId

Our Recommendation of queries to create the indexes:-

db.getCollection("textwidgetentity").createIndex( { "LocaleId": 1 } )

db.getCollection("textwidgetentity").createIndex( { "PortalId": 1 } )

db.getCollection("textwidgetentity").createIndex( { "VersionId": 1 } )

db.webstoreentity.createIndex({PortalId: 1, LocaleId: 1, PublishState: 1})

WebstoreEntity

  1. Indexes needed
    1. PortalId
    2. LocaleId
    3. PublishState

Our Recommendation of queries to create the indexes:-

db.getCollection("webstoreentity").createIndex( { "PortalId": 1 } )

db.getCollection("webstoreentity").createIndex( { "LocaleId": 1 } )

db.getCollection("webstoreentity").createIndex( { "PublishState": 1 } )

Steps to create a batch file:

  1. Set the database name in createindex.js file (use < database name>)
  2. Move createindex.js and createindex.bat file in “C:\Program Files\MongoDB\Server\3.2\bin”
  3. Run the createindex.bat file after publishing the store with the catalog to create the indexes in the database.

solid black circle

 

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.