Skip to content

Add index on the product collections field #101

@Alexandrbig1

Description

@Alexandrbig1

Priority: High
Difficulty: Intermediate
Type: Backend (Node.js + MongoDB + Mongoose)


Description

We need to add an index on the collections field in the Product schema.
This will improve performance for queries like /api/collections/:name since contributors and users will often fetch products by collection.


Implementation Details

  1. Update Product Schema

    • Current field:
      collections: { type: [String], default: [] }
    • Add an index:
      productSchema.index({ collections: 1 });
  2. Verify Index Creation

    • After updating schema, restart backend.
    • Run in Mongo shell or Compass:
      db.products.getIndexes()
      You should see the new index for collections.
  3. Testing

    • Query endpoint /api/collections/:name.
    • Ensure API works as before.
    • Confirm queries run faster in Mongo logs / Compass (optional).

Acceptance Criteria

  • collections field has an index in MongoDB.
  • Queries to /api/collections/:name work as expected.
  • Verified via db.products.getIndexes() that index exists.
  • Code passes existing ESLint/Prettier rules.

Metadata

Metadata

Assignees

Labels

apiAPI endpoints & integrationbackendIssues related to backendhacktoberfestSpecial issue for Hacktoberfesthacktoberfest-2025Special issue for Hacktoberfest 2025mongodbMongoDB & database managementmongooseMongoDB ODM / schema & model work (queries, models, migrations)node.jsBackend JavaScript / runtime (Express, APIs, server work)priority: mediumImportant but not urgent

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions