Skip to content

Commit

Permalink
Support 1.9 sharded output in validate_collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
behackett committed Apr 29, 2011
1 parent 3a3584e commit 1b52371
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pymongo/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,23 @@ def validate_collection(self, name_or_collection, full=False):

result = self.command("validate", unicode(name), full=full)

valid = True
# Pre 1.9 results
if "result" in result:
info = result["result"]
if info.find("exception") != -1 or info.find("corrupt") != -1:
raise CollectionInvalid("%s invalid: %s" % (name, info))
# Post 1.9 sharded results
elif "raw" in result:
for repl, res in result["raw"].iteritems():
if not res.get("valid", False):
valid = False
break
# Post 1.9 non-sharded results.
elif not result.get("valid", False):
valid = False

if not valid:
raise CollectionInvalid("%s invalid: %r" % (name, result))

return result
Expand Down

0 comments on commit 1b52371

Please sign in to comment.