Useful scripts for administrate and operate MongoDB.
show_collections_size.js
Show collections size in MB
Replace to your database name.
Example:
mongo get_collections_size.js
show_slow_operations.js
Show operations running over x seconds.
Example:
mongo show_slow_operations.js
find_random_document.js
Finds a random document according to a number of records in a collection.
kill_slow_operations.js
Kill all operations running over x seconds.
Example:
mongo kill_slow_operations.js
show_parameters.js
Show all MongoDB parameters.
Example:
mongo show_parameters.js
set_parameter_loglevel.js
Sets verbosity of the logging, specifying an integer between 0 and 5 where 5 is the most verbose.
Example:
mongo set_parameter_loglevel.js
repair_database.js
Server side to do shrink and repair database.
Replace to your database and collection names.
Example:
mongo repair_database.js
show_all_dbstats.js
Show all paramaters and stats from database.
Example:
mongo show_all_dbstats.js > all_stats.log
index_replicate.js
Copies the indexes from one instance to another.
Set variables:
drop_indexes_before = [bool];
host_name_master = [host_from];
db_name_master = [db_from];
host_name_replica = [host_to];
db_name_replica = [db_to];
Example:
mongo index_replicate.js
invert_hidden_members.js
Invert hidden/votes/priority members in a replica set
members DC1: {"hidden" : false, "priority" : 1, "votes" : 1}
members DC2: {"hidden" : true, "priority" : 0, "votes" : 0}
Example:
mongo --host mongodbhost:27017 -u user -p senha invert_hidden_members.js