While trying to clean cleanupOrphaned in my cluster enter image description here

I am getting this error.

  • Can you confirm your MongoDB server version with db.version() in the mongo shell? Are you connected to a mongos or a mongod? – Stennie Nov 28 '17 at 3:10
  • 1
    I guess that you are using mongodb 2.4 version, what didn't have cleanupOrphaned command, yet. If not, at least you have one error. That panelist_id should be panelist_id.collection, if panelist_id is database. – JJussi Nov 28 '17 at 4:01
  • My vesrion is 3.4.3 i have tried with transam_db.panelist (as my database.colection) but i am finding the same error message as (no such cmd: cleanupOrphaned) – ashk Nov 29 '17 at 8:02


Step 1. database and collection must be originally created (or sharded) thru mongoS

Step 2. command db.runCommand({cleanupOrphaned: "test.collection"}) must be ran on individual shard node (if replica set, then primary) at admin database. Not on mongoS, if you run that command on mongoS, you get that error message (and of course that error don't tell you that mongos cannot support that command).

#>mlaunch init --sharded 2 --single
launching: mongod on port 27018
launching: mongod on port 27019
launching: config server on port 27020
replica set 'configRepl' initialized.
launching: mongos on port 27017
adding shards.

#>mongo --port 27017
MongoDB shell version v3.4.6
connecting to: mongodb://
MongoDB server version: 3.4.6
MongoDB Enterprise mongos> use test
switched to db test
MongoDB Enterprise mongos> db.collection.insert({})
WriteResult({ "nInserted" : 1 })

#> mongo --port 27018 
MongoDB shell version v3.4.6
connecting to: mongodb://
MongoDB server version: 3.4.6
MongoDB > use admin
switched to db admin
MongoDB > db.runCommand( {cleanupOrphaned: "test.collection"})
{ "ok" : 1 }
| improve this answer | |
  • what is the procedure to run it from mongos – ashk Dec 20 '17 at 12:37
  • You cannot run it in the mongos. It must be run at every shard individually. If you try to run, you get error message as you did. – JJussi Dec 20 '17 at 22:08
  • ..but you can of course create connection from mongos to individual replica set primary and run command then. Result is same. – JJussi Dec 20 '17 at 22:55
  • while runnig the above command in my cluster i am getting rs1:primary>db.runCommand( {cleanupOrphaned: "tans.panelist"}) {"stoppedAtKey" : { "panelist_id : 38112 }, "ok' : 1} rs2:primary>db.runCommand( {cleanupOrphaned: "tans.panelist"}) {"stoppedAtKey" : { "panelist_id : 28741 }, "ok' : 1} is this the correct result – ashk Dec 28 '17 at 11:56
  • Yes, result is OK:1, so command was successful. – JJussi Dec 28 '17 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.