Skip to content

Latest commit

 

History

History
122 lines (88 loc) · 6.19 KB

README.md

File metadata and controls

122 lines (88 loc) · 6.19 KB

MongoDB Support Tools

getMongoData.js

Description

getMongoData.js is a utility for gathering information about how a running MongoDB deployment has been configured and for gathering statistics about its databases, collections, indexes, and shards.

For sample output, see getMongoData.log.

Usage

To execute on a locally-running mongod or mongos on the default port (27017) without authentication, run:

mongo --quiet --norc getMongoData.js > getMongoData-output.json

To execute on a remote mongod or mongos with authentication (see the next section for the minimum required permissions), run:

mongo HOST:PORT/admin -u ADMIN_USER -p ADMIN_PASSWORD --quiet --norc getMongoData.js > getMongoData-output.json

If ADMIN_PASSWORD is omitted, the shell will prompt for the password.

To have the output be in a more human-readable (non-JSON format), modify the above commands to include the following --eval option, as demonstrated for the local execution:

mongo --eval "var _printJSON=false;" getMongoData.js > getMongoData-output.log

To have a mongos for a sharded cluster output full details of chunk distribution across shards, include var _printChunkDetails=true in the --eval option:

mongo --quiet --norc --eval "var _printChunkDetails=true; var _ref = 'Support Case NNNNN'" getMongoData.js > getMongoData-output.json

More Details

getMongoData.js is JavaScript script which must be run using the mongo shell against either a mongod or a mongos.

Minimum required permissions (see MongoDB Built-In Roles):

  • A database user with the backup, readAnyDatabase, and clusterMonitor roles. These are essentially read-only roles except the backup role allows writes to two MongoDB system collections - admin.mms.backup and config.settings. The backup role is necessary in order for the script to output the number of database users and user-defined roles configured.
  • A root/admin database user may be used as well.

Example command for creating a database user with the minimum required permissions:

db.getSiblingDB("admin").createUser({
    user: "ADMIN_USER",
    pwd: "ADMIN_PASSWORD",
    roles: [ "backup", "readAnyDatabase", "clusterMonitor" ]
  })

The most notable methods, commands, and aggregations that this script runs are listed below.

Server Process Config & Stats

Replica Set Config & Stats

Database Users and User-Defined Roles (the count only)

Database, Collection, and Index Config & Stats

Sharding Config & Stats

  • Queries and aggregations on various collections in the MongoDB config database, including the "version", "settings", "routers", "shards", "databases", "chunks", and "tags" collections.

Queryable Encryption (QE) Config

  • db.getCollectionInfos()
  • Performs queries and aggregations on QE collections and auxiliary collections in all databases. The output is an array of objects, each containing information about a queryable encrypted collection.

Additional Notes

  • This script should take on the order of seconds to run.
  • If your deployment has more than 2500 collections, this script will by default fail.

License

Apache 2.0

DISCLAIMER

Please note: all tools/ scripts in this repo are released for use "AS IS" without any warranties of any kind, including, but not limited to their installation, use, or performance. We disclaim any and all warranties, either express or implied, including but not limited to any warranty of noninfringement, merchantability, and/ or fitness for a particular purpose. We do not warrant that the technology will meet your requirements, that the operation thereof will be uninterrupted or error-free, or that any errors will be corrected.

Any use of these scripts and tools is at your own risk. There is no guarantee that they have been through thorough testing in a comparable environment and we are not responsible for any damage or data loss incurred with their use.

You are responsible for reviewing and testing any scripts you run thoroughly before use in any non-testing environment.

Thanks,
The MongoDB Support Team