• mongodb 的备份恢复导入与导出


    导入导出
    use hndb;

    db.s.save({name:'李四',age:18,score:80,address:'郑州'});
    db.s.save({name:'李三',age:8,score:50,address:'郑州'});
    db.s.save({name:'张三',age:38,score:20,address:'天津'});
    db.s.save({name:'赵六',age:28,score:70,address:'郑州'});
    db.s.save({name:'王五五',age:19,score:90,address:'北京'});


    只导出name字段
    旧 mongoexport localhost:27017/admin -d hndb -c s -u admin -p admin -o c:s.json -f name

    新 只导出name,age
    mongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:j.js /f name,age

    导出所有属性
    mongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:j.js


    数据导入
    旧mongoimport -d shop -c student -u user -p shop --directoryperdb c:student.json

    mongoimport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s c:j.js

    删除数据库,db.dropDatabase();
    备份与恢复
    导出帮助到本地
    1. F:mongodbin>mongodump.exe --help >f:/mongodump-help.txt
    2. F:mongodbin>mongorestore.exe --help >f:/mongorestore-help.txt


    备份
    mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /o c:/

    备份指定库指定表 hndb 集合s 压缩备份
    mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /c s /o c:/ /gzip


    备份指定库指定表 hndb 所有信息 备份到c:/hndb.zip文件中
    mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip

    恢复
    mongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir c:/hndb/

    恢复指定的备份,gzip格式
    mongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip

    恢复 hndb 所有信息 从文件c:/hndb.zip
    mongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip



    数据库的导出

    1. F:mongodbin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
    2. tionDatabase:admin /d hndb /o c:/


    删除表
    > db.book.drop();
    true
    删除库
    > db.dropDatabase();
    { "dropped" : "hndb", "ok" : 1 }
    删除库表,然后备份恢复
    1. F:mongodbin>mongorestore /h localhost /port 27017 /u admin /p admin /authent
    2. icationDatabase:admin /d hndb /dir c:/hndb/
    压缩文件的导出
    1. 备份指定库指定表 hndb 所有信息 备份到c:/hndb.zip文件中
    2. mongodump /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
    删除库表,压缩文件的导入
    1. 恢复 hndb 所有信息 从文件c:/hndb.zip
    2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
    只导出stu压缩文件到hndb里面
    1. F:mongodbin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
    2. tionDatabase:admin /d hndb /c stu /o c:/ /gzip
    恢复指定的备份,gzip格式
    1. 恢复指定的备份,gzip格式
    2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip







  • 相关阅读:
    模拟——1031D
    线性dp——cf1032
    莫比乌斯反演——专题练习
    数论,质因数,gcd——cf1033D 好题!
    连通图,set——cf1037E
    线段树动态开点——cf1045G
    跳表上线性dp——1150D 好题!
    高斯消元求主元——模意义下的消元cf1155E
    汽车长期停放,毁车没商量?
    驾校都是错的?这才是日常驾驶正确的换挡方式
  • 原文地址:https://www.cnblogs.com/lsr111/p/4615578.html
Copyright © 2020-2023  润新知