Overview
PyqDeck uses MongoDB Atlas as its production database provider and Mongoose as the Object Data Modeling (ODM) library for Node.js.Production Setup (MongoDB Atlas)
- Cluster: We use a multi-region cluster for high availability and low latency.
- Connection: Managed via the
MONGODB_URIenvironment variable. - Security:
- IP Whitelisting: Only authorized application servers and CI/CD runners can connect.
- Authentication: SCRAM-SHA-1 or X.509 certificates.
- Encryption: Data is encrypted at rest (AES-256) and in transit (TLS/SSL).
Connection Management
The database connection is initialized inbackend/src/database.js.
- Singleton Pattern: We ensure only one connection instance exists throughout the application lifecycle.
- Configuration:
Indexing Strategy
To ensure high performance as the dataset grows, we define indexes in our Mongoose models:- Unique Indexes: On slugs and email addresses.
- Compound Indexes: For common query patterns (e.g.,
universityId+branchId+semesterId). - TTL Indexes: For temporary data like OTPs (if stored in MongoDB).
- Text Indexes: For basic global search functionality across universities and subjects.
Testing with mongodb-memory-server
For unit and integration tests, we do not use a live MongoDB instance. Instead, we usemongodb-memory-server.
Benefits
- Isolation: Each test run starts with a clean, empty database.
- Speed: Operations are performed in memory, making tests significantly faster.
- Reliability: Tests don’t fail due to network issues or shared state in a physical dev database.
Setup (backend/tests/setup.js)
The test runner automatically:
- Starts an in-memory MongoDB instance.
- Sets the
MONGODB_URIto the memory server’s address. - Clears all collections between test cases to ensure idempotency.
- Shuts down the server after all tests are complete.

