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:

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

Category Entity

  1. Indexes needed
  • DisplayOrder
  • ZnodeCategoryId
  • ZnodeCatalogId
  • LocaleId
  • VersionId
  • IsActive
  1. Order By
  • 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
  • CreatedDate
  1. Order By
  • CreatedDate

Our Recommendation of queries to create the indexes:-

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

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

VersionEntity

  1. Indexes needed
  • ZnodeCatalogId
  • RevisionType
  • 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 } )

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

ConfigurableProductEntity

  1. Indexes needed
  • ZnodeProductId
  • VersionId

Our Recommendation of queries to create the indexes:-

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

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

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

SEOEntity

  1. Indexes needed
  • PortalId
  • SEOTypeName
  • LocaleId
  • VersionId
  • 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 } )

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

AddonEntity

  1. Indexes needed
  • DisplayOrder
  • ZnodeProductId
  • LocaleId
  • VersionId
  • RequiredType
  1. Order By
  • 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 } )

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

ProductEntity

  1. Indexes needed
  • ZnodeProductId
  • SKULower
  • ZnodeCatalogId
  • ZnodeCategoryIds
  • LocaleId
  • IsActive
  • VersionId
  • 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 } )

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

ContentPageConfigEntity

  1. Indexes needed
  • PortalId
  • IsActive
  • ProfileId
  • 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 } )

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

TextWidgetEntity

  1. Indexes needed
  • LocaleId
  • PortalId
  • 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 } )

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

WebstoreEntity

  1. Indexes needed
  • PortalId
  • LocaleId
  • 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.