0

Is there an API know to anyone to repair mongodb is case of corrupt databases through ruby-mongodb-driver.

Looking through the documentation seem that there isn't

can anyone confirm.

Or can anyone suggest me a better way to repair mongod database .

the currently I knew

./mongod --repair options

./mongo

> use [database]
> db.repairDatabase()

I also see a shell options

 ./mongo --help 

options:
  --shell               run the shell after executing files

How can I write a script(.js) to repair the given database

Viren
  • 5,812
  • 6
  • 45
  • 98

1 Answers1

3

For the mongo shell, the database name can be given as an optional argument. Here is a shell script that should make this clear.

repair.sh

#!/bin/sh
if [ $# -lt 1 ]
then    echo "$0 - repair mongodb database"
        echo "usage: $0 database-name"
        exit 1
fi
mongo $1 --eval 'printjson(db.repairDatabase())'

Here is a ruby 1.9 equivalent.

repair.rb

#!/bin/env ruby
require 'mongo'
if ARGV.length < 1
    puts "$0 - repair mongodb database"
    puts "usage: $0 database-name"
    exit 1
end
db = Mongo::Connection.new[ARGV[0]]
puts db.command({repairDatabase: 1})

There's more info in the FAQ and documentation for DB.

http://api.mongodb.org/ruby/current/file.FAQ.html

http://api.mongodb.org/ruby/current/Mongo/DB.html

Navigation to some documentation isn't obvious - we'll look into making it better.

Gary Murakami
  • 3,392
  • 1
  • 16
  • 20