How to Fix MongoDB Error 169 (CommandOnShardedViewNotSupportedOnMongod)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mongodb error 169 when a client runs a command on a sharded view against a shard node. You fix this error by routing your queries through a query router instead of the shard server. In MongoDB, this failure carries the official name CommandOnShardedViewNotSupportedOnMongod. It stops commands that need cluster-wide view routing from running on a single database daemon. When an app or engineer talks straight to a shard, the node rejects the view query. What causes mongodb error 169 in a

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 get mongodb error 169 when a client runs a command on a sharded view against a shard node. You fix this error by routing your queries through a query router instead of the shard server.

In MongoDB, this failure carries the official name CommandOnShardedViewNotSupportedOnMongod. It stops commands that need cluster-wide view routing from running on a single database daemon. When an app or engineer talks straight to a shard, the node rejects the view query.

What causes mongodb error 169 in a sharded cluster

A sharded cluster splits data across multiple database nodes. A view is a read-only object built from an aggregation pipeline on another collection. When that base collection is sharded, the view counts as a sharded view.

Single shard nodes do not hold the full routing table for all chunks in the cluster. Only the query router knows how to merge results from every shard. When a query hits a shard node directly, the engine sees that the view relies on sharded data. The node stops the request and returns error code 169 to tell the caller to use a router.

This issue often starts when an engineer opens a direct maintenance session to a single shard host. It also happens when an app connection string lists shard hostnames instead of router hostnames. Monitoring scripts that poll individual nodes can also hit this error when they inspect database views.

How to diagnose and fix the failure in production

First, check the connection target used by the failing app or user session. Look at the hosts listed in your client settings. Verify that every host points to a query router instance and not to a shard replica set member.

Next, inspect the view definition to see which underlying collection it reads. If that collection is sharded, any read command on the view must go through the router layer. Update your client connection strings so all app traffic flows through the router tier.

Customer Support Access to Production + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Keep your access rules tight while you fix the network path. MongoDB grants access through role-based authorization on defined resources down to the collection level. You do not need to grant write or admin privileges to fix view routing errors.

Assign the built-in read role to users and services that only query views. The read role grants actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream on non-system collections. It leaves out insert, update, remove, and dropCollection actions, which keeps production data safe during repairs.

Preventing direct shard queries from user sessions

Engineers often connect to individual shard nodes during an incident to check local performance. If they run a find command on a sharded view during that session, error 169 appears right away. You can prevent this mistake by standardizing how your team connects to database clusters.

Give developers and support staff a single entry point that always routes to the query router tier. Remove direct network paths from user laptops to underlying shard servers. When every session flows through the router, sharded views work as expected and role checks stay consistent across the cluster.

Inspect MongoDB wire traffic in flight

Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.

First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.

Frequently asked questions

What does CommandOnShardedViewNotSupportedOnMongod mean?

It means a command targeted a view backed by a sharded collection while connected directly to a shard node. The shard node cannot resolve the view alone and requires a query router to handle the request.

Do I need higher database privileges to fix mongodb error 169?

No, changing user roles will not solve a routing path error. A user with the standard read role can query a sharded view once connected to the query router.

Can monitoring tools trigger error code 169?

Yes, health scripts that connect to each shard node and scan all collections and views will trigger this error. Configure those scripts to skip sharded views on shard nodes or run view checks through the router.

The query runs. The emails stay hidden.