Download

MongoServerError: ns not found

The command (dropIndex, renameCollection, collMod, validate, $collStats…) needs a collection that doesn’t exist in the database you’re using. Check the database and collection names, including case; queries and inserts never raise it.

MongoDB error 26· Tested on MongoDB 8.0.32 (mongosh 2.12.0)· Updated 11 October 2026

ns not found seo_err_mongo.missing

What it means

A namespace (“ns”) is a database and a collection together: shop.orders. Some commands work on an existing collection and fail when there isn’t one, with code 26, NamespaceNotFound. The message varies with the command, and usually names the namespace:

CommandMessage on MongoDB 8.0
dropIndex, dropIndexesns not found seo_err_mongo.missing
getIndexes (listIndexes)ns does not exist: seo_err_mongo.missing
collModns does not exist
renameCollectionSource collection seo_err_mongo.missing does not exist
validateCollection 'seo_err_mongo.missing' does not exist to validate.
stats(), $collStats… Collection [seo_err_mongo.missing] not found.

Ordinary reads and writes don’t raise it: a find on a missing collection returns nothing, and an insert creates the collection. So the error points at admin work: indexes, renames, schema changes, statistics.

Before MongoDB 7.0, the drop command also failed with ns not found for a missing collection (some drivers and shells hid that by returning false); since 7.0 it succeeds.

Common causes

  1. The wrong database. The connection string’s path (or use) picks a different database from the one holding the collection, for example test, the default when the URL has none.
  2. A misspelt or wrongly cased name. Names are case-sensitive: Orders and orders are two collections. Mongoose also pluralises and lowercases model names (User becomes users).
  3. The collection doesn’t exist yet: a migration or test runs dropIndex, collMod or a rename before anything has written to it.
  4. It was already dropped or renamed, by an earlier run of the same script or by another process.
  5. Old servers and drivers: test teardown that drops collections that were never created fails on servers before 7.0.

How to fix it

Check where you are

db.getName()
db.getCollectionNames()

On the command line, mongosh "<connection string>" --eval 'db.getName()' shows which database the URL selects. If the collection is elsewhere, put that database in the connection string’s path, or use db.getSiblingDB("<database>").

Find the collection by name

To search every database you can see for a name, ignoring case:

db.adminCommand({ listDatabases: 1, nameOnly: true }).databases.forEach(d =>
  db.getSiblingDB(d.name).getCollectionNames()
    .filter(c => c.toLowerCase() === "orders")
    .forEach(c => print(`${d.name}.${c}`))
)

Create it first, or skip when it’s missing

In scripts and migrations, check before you act:

if (db.getCollectionNames().includes("orders")) {
  db.orders.dropIndex("placedAt_1")
}

Or create the collection explicitly with db.createCollection("orders") before collMod or index changes. In application code, catch code 26 where a missing collection is fine (for example in test teardown) and let other errors through.

Use the name Mongoose uses

Model.collection.collectionName prints the real name. To choose it yourself, pass it as the third argument: mongoose.model("User", schema, "User").

Reproduce it

MongoDB 8.0.32, mongosh 2.12.0, in a database with no collection missing:

db.missing.dropIndex("a_1")
MongoServerError[NamespaceNotFound]: ns not found seo_err_mongo.missing

The error’s code was 26. The other messages in the table came from getIndexes(), collMod, renameCollection("other"), validate() and stats(). reIndex() said collection does not exist. Meanwhile db.missing.drop() returned true, find() returned nothing and countDocuments() returned 0, all without an error.

In Inlet

Inlet shows MongoDB collections as tables, so you can see which collections a database holds and how their names are spelt. Queries use mongosh syntax, so db.getName(), db.getCollectionNames() and the index commands above run in a query tab.

Inlet: a database client for the Mac

One native app for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and Redis. It explains errors where they happen, holds your edits until you save them, and keeps production read-only until you say so.

Version 0.1.0 · macOS 26 Tahoe or later · Apple silicon and Intel