Skip to main content

Get Usage Stats

Retrieves usage statistics for all projects owned by the authenticated user, sorted by total requests.

Headers

string
required
Bearer token for authentication

Response

boolean
Indicates if the request was successful
number
Cumulative total requests across all projects
array
Array of all projects with their usage statistics, sorted by totalRequest in descending order

Implementation Details

Query Logic

  • Fetches all projects owned by the authenticated user
  • Excludes projects with status deleted
  • Results are sorted by totalRequest in descending order (highest usage first)
  • Uses lean queries for optimal performance

Selected Fields

The query selects the following fields from the Project model:
  • name
  • projectType
  • status
  • totalRequest
  • plan
  • createdAt
  • updatedAt

Usage Calculation

  • totalRequests: Calculated using reduce to sum the totalRequest field across all projects
  • projectStats: Each project’s totalRequest field defaults to 0 if not set or null
  • Projects with no requests will show totalRequest: 0

Use Cases

  • Monitor which projects are receiving the most traffic
  • Identify unused or low-traffic projects
  • Track overall platform usage across all deployments
  • Compare usage across different project types and plans
  • Make data-driven decisions about resource allocation

Error Response