Drop un-sharded database that I faced strange error

I have 3 shard cluster
connect to mongos and I tried to drop an un-sharded database
when I dropped database I faced a strange error below

> db.dropDatabase()
MongoServerError: This is not the primary shard for db unfied_dashboard expected: shard2set shardId: shard1set

how can I change the shard set via mongos?

[direct: mongos] unfied_dashboard> sh.status()
shardingVersion
{
  _id: 1,
  minCompatibleVersion: 5,
  currentVersion: 6,
  clusterId: ObjectId("62f397da4459adfb1985fe6a")
}
---
shards
[
  {
    _id: 'shard1set',
    host: 'shard1set/host01-01-:1111,host01-02-:1111',
    state: 1,
    topologyTime: Timestamp({ t: 1660138052, i: 4 })
  },
  {
    _id: 'shard2set',
    host: 'shard2set/host02-01-:1111,host02-02-:1111',
    state: 1,
    topologyTime: Timestamp({ t: 1660782013, i: 3 })
  },
  {
    _id: 'shard3set',
    host: 'shard3set/host03-01-:1111,host03-02-:1111',
    state: 1,
    topologyTime: Timestamp({ t: 1660782222, i: 1 })
  }
]
---
active mongoses
[ { '6.0.0': 3 } ]
---
autosplit
{ 'Currently enabled': 'yes' }
---
balancer
{
  'Currently enabled': 'yes',
  'Currently running': 'no',
  'Failed balancer rounds in last 5 attempts': 0,
  'Migration Results for the last 24 hours': 'No recent migrations'
}
---
databases
[
  {
    database: { _id: 'config', primary: 'config', partitioned: true },
    collections: {
      'config.system.sessions': {
        shardKey: { _id: 1 },
        unique: false,
        balancing: true,
        chunkMetadata: [
          { shard: 'shard1set', nChunks: 342 },
          { shard: 'shard2set', nChunks: 341 },
          { shard: 'shard3set', nChunks: 341 }
        ],
        chunks: [
          'too many chunks to print, use verbose if you want to force print'
        ],
        tags: []
      }
    }
  },
  {
    database: {
      _id: 'test',
      primary: 'shard2set',
      partitioned: false,
      version: {
        uuid: UUID("f9e8580c-0a3d-4fc6-98a5-a80745ce406a"),
        timestamp: Timestamp({ t: 1660899990, i: 1 }),
        lastMod: 1
      }
    },
    collections: {}
  },
  {
    database: {
      _id: 'test1',
      primary: 'shard2set',
      partitioned: false,
      version: {
        uuid: UUID("b4ea4074-b609-49d1-9753-8747f35b6153"),
        timestamp: Timestamp({ t: 1660901440, i: 1 }),
        lastMod: 1
      }
    },
    collections: {}
  },
  {
    database: {
      _id: 'test2',
      primary: 'shard2set',
      partitioned: false,
      version: {
        uuid: UUID("da4dcf6f-99e7-4589-ab08-ea70b817a62c"),
        timestamp: Timestamp({ t: 1660902134, i: 3 }),
        lastMod: 2
      }
    },
    collections: {}
  },
  {
    database: {
      _id: 'unfied_dashboard',
      primary: 'shard2set',
      partitioned: false,
      version: {
        uuid: UUID("f6a4e39f-dea0-49e0-bf90-80e5f41a88bf"),
        timestamp: Timestamp({ t: 1660885444, i: 1 }),
        lastMod: 1
      }
    },
    collections: {}
  },
  {
    database: {
      _id: 'unified_dashboard',
      primary: 'shard3set',
      partitioned: false,
      version: {
        uuid: UUID("57b5e1bf-ae1b-4096-8b75-eb50a9cb6462"),
        timestamp: Timestamp({ t: 1660882030, i: 2 }),
        lastMod: 1
      }
    },
    collections: {}
  }
]
[direct: mongos] unfied_dashboard> db.dropDatabase()
MongoServerError: This is not the primary shard for db unfied_dashboard expected: shard2set shardId: shard1set

Hello :wave: @turbostar777,

Welcome to the MongoDB Community forums :sparkles:

I suspect this error because mongos might have stale information, possibly the primary shard actually moved but mongos is still having stale information. So I’ll suggest you try flushRouterConfig to flush the cache for all databases and their collections using the command:

db.adminCommand("flushRouterConfig")

And, try to drop the database again.

I hope it helps!

Thanks,
Kushagra

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.