Skip to content

Instantly share code, notes, and snippets.

@mfo
Created April 28, 2012 19:29
Show Gist options
  • Save mfo/2521548 to your computer and use it in GitHub Desktop.
Save mfo/2521548 to your computer and use it in GitHub Desktop.
mongo utilities
# dropdb from console
$> mongo --eval "db.dropDatabase();" databasename
# restore a db from a backup
$> mongorestore -vvv sharypic_development
# run mongo console
$> mongo
# a few usefull command on mongo cli
show dbs
use sharypic_development
# add user
db.addUser("sharypic", "sharypic")
# adding sparse index
db.users.dropIndex("invite_code_1")
db.users.ensureIndex({invide_code: 1}, {sparse: true, unique: true})
# rename a datbase
use 'sharypic-staging'
db.copyDatabase("sharypic-staging", "sharypic_development", this)
db.getCollecitonNames()
# querying object id
{_id: ObjectId('blah')}
# removing stuffs
db.pictures.remove({ $and: [ {"event_id": ObjectId('4e11adb84fcd230001000044')}, {"_type": {$ne: "TwitterSource"}}] })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment