Skip to content

Instantly share code, notes, and snippets.

@wolf-mtwo
Last active August 29, 2015 14:10
Show Gist options
  • Save wolf-mtwo/0fb2178192346877bf5a to your computer and use it in GitHub Desktop.
Save wolf-mtwo/0fb2178192346877bf5a to your computer and use it in GitHub Desktop.
MONGO
/* 0 */
{
    "_id" : ObjectId("54ba5cb66d1a62a80d3ed4f7"),
    "schedule" : ObjectId("54b592f211c7b1280663d0a3"),
    "group" : ObjectId("54b575ea0ae9f21c1b5bc3d2"),
    "participant" : ObjectId("54ba59a0f31d635819bb9024"),
    "status" : "10",
    "created" : ISODate("2015-01-17T12:59:34.510Z"),
    "__v" : 0
}

/* 1 */
{
    "_id" : ObjectId("54ba5cb66d1a62a80d3ed4f8"),
    "schedule" : ObjectId("54b592f211c7b1280663d0a3"),
    "group" : ObjectId("54b575ea0ae9f21c1b5bc3d2"),
    "participant" : ObjectId("54ba06133e2c4e94090c29ff"),
    "status" : "10",
    "created" : ISODate("2015-01-17T12:59:34.841Z"),
    "__v" : 0
}

/* 2 */
{
    "_id" : ObjectId("54bb0b6cb0b4a73c1b42cc91"),
    "schedule" : ObjectId("54b5932dbeb637f010c0b899"),
    "group" : ObjectId("54b575ea0ae9f21c1b5bc3d2"),
    "participant" : ObjectId("54b576020ae9f21c1b5bc3d3"),
    "status" : "10",
    "created" : ISODate("2015-01-18T01:25:00.768Z"),
    "__v" : 0
}
db.attendances.aggregate([
    {
        $match: {
            group: ObjectId("54b575ea0ae9f21c1b5bc3d2")
        }
    },{
        $group: {
            _id: '$schedule',
            participants: {$push: '$participant'}
        }
    }
])
db.attendances.aggregate([
    {
        $match: {
            group: ObjectId("54b575ea0ae9f21c1b5bc3d2")
        }
    },{
        $group: {
            _id: '$status',
            participant: {$push: '$participant'}
        }
    }
])

mongo config

back up

mongodump --db blog
mongodump --db {name}

remote

mongodump --username wolf --password ???? --host 0.0.0.0 --db {name}

restaurar copias de seguridad

mongorestore --host localhost --port 27017 ./backup/
mongorestore --host localhost --port 27017 .

restore

sudo -u mongodb mongod --repair -dbpath /var/lib/mongodb

eliminar todas mas DBS

var dbs = db.getMongo().getDBNames()
for(var i in dbs){
    db = db.getMongo().getDB( dbs[i] );
    print( "dropping db " + db.getName() );
    db.dropDatabase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment