Common issues and solutions for DatabaseKit.
- Installation Issues
- Connection Issues
- Configuration Issues
- Query Issues
- TypeScript Issues
- NestJS Integration Issues
- Performance Issues
- Getting Help
Error:
npm WARN @ciscode/database-kit@1.0.0 requires a peer of @nestjs/common@^10.0.0 || ^11.0.0 but none is installed.
Solution:
npm install @nestjs/common @nestjs/core reflect-metadataError (MongoDB):
Cannot find module 'mongoose'
Error (PostgreSQL):
Cannot find module 'pg'
Solution:
# For MongoDB
npm install mongoose
# For PostgreSQL
npm install pgError:
tsc-alias: command not found
Solution:
npm install -D tsc-aliasError:
MongoServerSelectionError: connect ETIMEDOUT
Possible Causes:
- Incorrect connection string
- Network/firewall blocking connection
- MongoDB Atlas IP whitelist
Solutions:
-
Verify connection string format:
mongodb://username:password@host:27017/database mongodb+srv://username:password@cluster.mongodb.net/database -
Check network connectivity:
ping your-mongo-host.com telnet your-mongo-host.com 27017
-
For MongoDB Atlas, add your IP to whitelist:
- Go to Network Access → Add IP Address
- Add current IP or
0.0.0.0/0for testing
Error:
Error: connect ECONNREFUSED 127.0.0.1:5432
Solutions:
-
Verify PostgreSQL is running:
# Linux/Mac pg_isready # Docker docker ps | grep postgres
-
Check connection string:
postgresql://username:password@localhost:5432/database -
Verify
pg_hba.confallows connections
Error (PostgreSQL):
error: no pg_hba.conf entry for host
Solution: Add SSL mode to connection string:
postgresql://user:pass@host:5432/db?sslmode=require
Error:
Error: Environment variable DATABASE_URL is not configured.
Solution:
-
Create
.envfile:DATABASE_TYPE=postgres DATABASE_URL=postgresql://user:pass@localhost:5432/mydb
-
Load environment variables:
// In main.ts (before NestJS bootstrap) import * as dotenv from 'dotenv'; dotenv.config();
-
Or use
@nestjs/config:@Module({ imports: [ ConfigModule.forRoot(), DatabaseKitModule.forRootAsync({ imports: [ConfigModule], useFactory: (config: ConfigService) => ({ config: { type: config.get('DATABASE_TYPE'), connectionString: config.get('DATABASE_URL'), }, }), inject: [ConfigService], }), ], })
Error:
Error: Invalid DATABASE_TYPE: "mysql". Must be "mongo" or "postgres".
Solution:
DatabaseKit only supports mongo and postgres. Check your DATABASE_TYPE env var.
Error:
Error: Field "secret_column" is not allowed for table "users".
Cause: You're querying a column not in the whitelist.
Solution: Add the column to your repository config:
const repo = db.createPostgresRepository({
table: 'users',
columns: ['id', 'name', 'email', 'secret_column'], // Add here
});Error:
CastError: Cast to ObjectId failed for value "invalid-id"
Solution: Validate IDs before querying:
import { isValidMongoId } from '@ciscode/database-kit';
if (!isValidMongoId(id)) {
throw new BadRequestException('Invalid ID format');
}
const user = await repo.findById(id);Error:
MongoServerError: E11000 duplicate key error
Solution:
-
Check for existing records before insert:
const exists = await repo.exists({ email }); if (exists) { throw new ConflictException('Email already exists'); }
-
Use the
DatabaseExceptionFilterto catch and format this error automatically.
Error:
Cannot find module '@adapters/mongo.adapter' or its corresponding type declarations.
Solution:
- Make sure
tsconfig.jsonhas path aliases configured - Run build with
tsc-alias:{ "scripts": { "build": "tsc && tsc-alias" } }
Error:
Property 'name' does not exist on type 'unknown'
Solution: Provide type parameter to repository:
interface User {
_id: string;
name: string;
email: string;
}
const repo = db.createMongoRepository<User>({ model: UserModel });
// Now repo methods return User typeError:
Nest could not find DATABASE_KIT_DEFAULT element
Cause: Module not imported in the correct order.
Solution:
Import DatabaseKitModule before modules that depend on it:
@Module({
imports: [
DatabaseKitModule.forRoot({ ... }), // First
UsersModule, // Then modules that use it
],
})
export class AppModule {}Error:
Circular dependency detected
Solution:
Use forwardRef:
@Injectable()
export class UserService {
constructor(
@InjectDatabase() private db: DatabaseService,
@Inject(forwardRef(() => OrderService)) private orders: OrderService,
) {}
}Issue: Database not accessible in all modules.
Solution:
DatabaseKitModule is @Global() by default. If you still have issues, check:
- Module is imported in root
AppModule - You're using
@InjectDatabase()decorator - The service is properly registered as a provider
Symptoms:
- Queries taking > 100ms
- High CPU on database server
Solutions:
-
Add indexes to frequently queried columns:
// MongoDB UserSchema.index({ email: 1 }); // PostgreSQL CREATE INDEX idx_users_email ON users(email);
-
Use pagination instead of
findAll:// ❌ Don't load all records const all = await repo.findAll(); // ✅ Use pagination const page = await repo.findPage({ page: 1, limit: 50 });
-
Select only needed columns (PostgreSQL):
// Limit columns in config columns: ['id', 'name'], // Only fetch these
Symptoms:
- Timeouts under load
- "Too many connections" errors
Solutions:
-
Check pool size configuration:
DATABASE_POOL_SIZE=20
-
Ensure connections are released (automatic with our adapters)
-
Monitor active connections:
-- PostgreSQL SELECT count(*) FROM pg_stat_activity;
- ✅ Check this troubleshooting guide
- ✅ Search existing issues
- ✅ Read the README
- ✅ Check NestJS documentation
When creating an issue, include:
- DatabaseKit version:
npm list @ciscode/database-kit - Node.js version:
node --version - NestJS version:
npm list @nestjs/core - Database type and version
- Minimal reproduction code
- Full error message and stack trace
- Expected vs actual behavior
- 🐛 Bug Reports: GitHub Issues
- 💬 Questions: GitHub Discussions
- 📧 Email: info@ciscod.com
Enable debug logging to diagnose issues:
import { Logger } from '@nestjs/common';
// Enable all log levels
Logger.overrideLogger(['log', 'error', 'warn', 'debug', 'verbose']);Or set environment variable:
DEBUG=*Last updated: January 2026