0

Currently we have a 4 shard cluster

Can you give me the procedure to check the orphaned documents in our cluster

And can you provide me the procedure to delete the orphaned documents in the cluster

Please find the below screen shot of our cluster

enter image description here

  • Which MongoDB version in your environment? – Md Haidar Ali Khan Nov 20 '17 at 7:43
  • my MongoDB vresion is 3.4.3 – ashk Nov 20 '17 at 8:25
0

Can you give me the procedure to check the orphaned documents in our cluster

As per MongoDB BOL Here On a sharded cluster, db.collection.count() can result in an inaccurate count if orphaned documents exist or if a chunk migration is in progress.

To avoid these situations, on a sharded cluster, use the $group stage of the db.collection.aggregate() method to $sum the documents. For example, the following operation counts the documents in a collection:

db.collection.aggregate(
   [
      { $group: { _id: null, count: { $sum: 1 } } }
   ]
)

To get a count of documents that match a query condition, include the $match stage as well:

db.collection.aggregate(
   [
      { $match: <query condition> },
      { $group: { _id: null, count: { $sum: 1 } } }
   ]
)

And can you provide me the procedure to delete the orphaned documents in the cluster

As per MongoDB BOL Here Deletes from a shard the orphaned documents whose shard key values fall into a single or a single contiguous range that do not belong to the shard. For example, if two contiguous ranges do not belong to the shard, the cleanupOrphaned examines both ranges for orphaned documents.

cleanupOrphaned has the following syntax:

db.runCommand( {
   cleanupOrphaned: "<database>.<collection>",
   startingFromKey: <minimumShardKeyValue>,
   secondaryThrottle: <boolean>,
   writeConcern: <document>
} )
  • if i give only minimum shard key value does it clear all the orphaned documents with out maximum shard key values. – ashk Nov 20 '17 at 8:27
  • @ashok kumar devalla, No. – Md Haidar Ali Khan Nov 20 '17 at 8:30
  • @ashok kumar devalla, You can also Remove Orphaned Documents for a Specific Range Or Remove All Orphaned Documents from a Shard.see the mention link – Md Haidar Ali Khan Nov 20 '17 at 8:34
  • what we should we add at secondaryThrottle: <boolean>,in boolean we should give yes and inwriteConcern: <document> in (document) what show we give in the palce of document – ashk Nov 22 '17 at 8:18

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.