79766920

Date: 2025-09-17 05:40:47
Score: 1
Natty:
Report link

The best way to reduce DB calls in a NodeJS + MongoDB role-based app is to store user roles in the JWT when the user logs in. Instead of querying the database on every request, you decode the token and check roles directly from it. This avoids extra DB calls and keeps things fast.

Just make sure tokens are securely signed and expire reasonably so role changes don’t go unnoticed.

Alternatively, you could use a cache like Redis if needed.

This is simple, efficient, and widely used in real projects.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Ashish Parakh