How to Fix MongoDB Error 13297 (DatabaseDifferCase)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 13297 when you try to use a database name with mixed letter casing. You can fix this DatabaseDifferCase error by matching the exact letter case of the existing database. Database servers keep strict rules for how they store names on disk. If one app writes to a lowercase name, another app cannot use uppercase letters for that same name. When two tools send different letter cases, the engine stops the second request right away. This stop protects your files from conflicts o

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mongodb error 13297 when you try to use a database name with mixed letter casing. You can fix this DatabaseDifferCase error by matching the exact letter case of the existing database.

Database servers keep strict rules for how they store names on disk. If one app writes to a lowercase name, another app cannot use uppercase letters for that same name. When two tools send different letter cases, the engine stops the second request right away. This stop protects your files from conflicts on the host storage system.

Why mongodb error 13297 happens in your cluster

The official server name for mongodb error 13297 is DatabaseDifferCase. The database engine tracks every existing database name in memory and on disk. Even if your disk supports different letter cases, the server blocks two names that only differ by case. For example, you cannot have one database named sales and another named Sales on the same cluster.

This problem often starts when a developer types a new connection string in an app. A tiny typo in a single uppercase letter makes the client ask for a brand new database. When the server sees that the name matches an older database in lowercase, it throws code 13297. Automated scripts and migration jobs also trigger this issue when they build names from user input.

Role rules can also point to the wrong database case. MongoDB grants access through roles that let users run actions on specific resources. Each role applies to the database where an admin defines it, down to the collection level. If a user role targets one letter case and the app queries another, the session will fail.

How to diagnose and fix the failure in production

First, check the exact database names that already live on your cluster. You do not need wide admin rights to check names and read data. The built-in read role lets you list collections and indexes on non-system collections. It also allows find queries, database stats, collection stats, and change streams without allowing data edits.

MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Compare the existing database name on the server with the name in your app settings. Look at your client settings, secret stores, and job scripts for any uppercase or lowercase mismatches. Once you spot the mismatch, update your app string so it matches the server name letter for letter. This simple text change fixes the error for most teams without touching any stored data.

Sometimes an empty database with the wrong letter case already sits on the server. In that case, a team member with write rights must clean it up. The readWrite role includes everything in the read role plus the power to change data. It allows insert, update, remove, create collection, create index, drop index, and drop collection actions. Always verify that the wrong database holds no real records before you remove any collections.

How to prevent database casing conflicts

Set a clear naming rule for every database and collection in your team docs. Many engineering teams force all database names to use lowercase letters only. Review new app settings during code review to catch uppercase typos before deployment. You can also lock down write roles so random apps cannot create new databases by mistake. Keep your self-hosted and cloud role definitions clean so every user connects to the exact right resource.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

What does the DatabaseDifferCase message mean?

DatabaseDifferCase is the official name for error code 13297 in the database server. It means your client asked for a database name that conflicts with the letter case of an existing database.

Can I fix this error without dropping my database?

Yes, you can fix the issue by updating the database name in your client connection settings. Make sure the letter case in your app matches the exact case already stored on the server.

Does the read role allow me to drop a collection with the wrong case?

No, the read role only grants read access and blocks insert, update, remove, and drop collection actions. You need a role with write privileges, such as readWrite, to drop collections or change data.

The query runs. The emails stay hidden.