Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2012 19:29
What would you like to do?
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.ensureIndex({invide_code: 1}, {sparse: true, unique: true})
# rename a datbase
use 'sharypic-staging'
db.copyDatabase("sharypic-staging", "sharypic_development", this)
# querying object id
{_id: ObjectId('blah')}
# removing stuffs{ $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