Skip to content

Instantly share code, notes, and snippets.

@etissieres
Last active August 29, 2015 13:56
Show Gist options
  • Save etissieres/9226076 to your computer and use it in GitHub Desktop.
Save etissieres/9226076 to your computer and use it in GitHub Desktop.
Mongo tips

Mongo tips

Sharding

Sharding status

sh.status()

Shards

use config
db.shards.find()

Sharded databases

use config
db.databases.find({partitioned: true})

Sharded collections

use config
db.collections.find({key: {$exists: true}})

Shard database

use admin
db.runCommand({enableSharding: 'DB_NAME'})

Shard collection

use admin
db.runCommand({shardCollection: 'DB_NAME.COL_NAME', key: SHARD_KEY})

Indexes

Collection indexes

use DB_NAME
db.COL_NAME.getIndexKeys()

Drop index

use DB_NAME
db.COL_NAME.dropIndex(INDEX)

Create index

use DB_NAME
db.COL_NAME.createIndex(INDEX)

Ensure index (create if not exist)

use DB_NAME
db.COL_NAME.ensureIndex(INDEX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment