Created
April 28, 2012 19:29
-
-
Save mfo/2521548 to your computer and use it in GitHub Desktop.
mongo utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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