mongodb 基础

mongodb 数据备份和恢复

mongodb 可以导出bson 和 json 两种格式的备份。bson为数据存储格式 less space but not readable

点击查看代码
mongodump --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies"

mongoexport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --collection=sales --out=sales.json

mongorestore --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies"  --drop dump

mongoimport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --drop sales.json

mongodb CRUD 不擅长

mongodb index 相关

创建索引会阻塞读写 注意使用"background" : true

点击查看代码
background 过程中可以通过
db.currentOp() 来查看进度
                {
                        "desc" : "conn7805468",
                        "threadId" : "140603841742592",
                        "connectionId" : 7805468,
                        "client" : "10.111.146.226:59984",
                        "appName" : "MongoDB Shell",
                        "clientMetadata" : {
                                "application" : {
                                        "name" : "MongoDB Shell"
                                },
                                "driver" : {
                                        "name" : "MongoDB Internal Client",
                                        "version" : "3.4.20"
                                },
                                "os" : {
                                        "type" : "Linux",
                                        "name" : "CentOS Linux release 7.6.1810 (Core) ",
                                        "architecture" : "x86_64",
                                        "version" : "Kernel 3.10.0-957.21.3.el7.x86_64"
                                }
                        },
                        "active" : true,
                        "opid" : 2136890871,
                        "secs_running" : 0,
                        "microsecs_running" : NumberLong(32),
                        "op" : "command",
                        "ns" : "admin.$cmd",
                        "query" : {
                                "currentOp" : 1
                        },
                        "numYields" : 0,
                        "locks" : {

                        },
                        "waitingForLock" : false,
                        "lockStats" : {

                        }
                },
                {
                        "desc" : "conn7805467",
                        "threadId" : "140603939641088",
                        "connectionId" : 7805467,
                        "client" : "10.111.146.226:59944",
                        "appName" : "MongoDB Shell",
                        "clientMetadata" : {
                                "application" : {
                                        "name" : "MongoDB Shell"
                                },
                                "driver" : {
                                        "name" : "MongoDB Internal Client",
                                        "version" : "3.4.20"
                                },
                                "os" : {
                                        "type" : "Linux",
                                        "name" : "CentOS Linux release 7.6.1810 (Core) ",
                                        "architecture" : "x86_64",
                                        "version" : "Kernel 3.10.0-957.21.3.el7.x86_64"
                                }
                        },
                        "active" : true,
                        "opid" : 2136753025,
                        "secs_running" : 124,
                        "microsecs_running" : NumberLong(124927372),
                        "op" : "command",
                        "ns" : "kidappoint.$cmd",
                        "query" : {
                                "createIndexes" : "kidappoint_log",
                                "indexes" : [
                                        {
                                                "key" : {
                                                        "stamp" : -1
                                                },
                                                "name" : "stamp_-1",
                                                "background" : true
                                        }
                                ]
                        },
                        "msg" : "Index Build (background) Index Build (background): 31647928/37672663 84%",
                        "progress" : {
                                "done" : 31647929,
                                "total" : 37672663
                        },
                        "numYields" : 248108,
                        "locks" : {
                                "Global" : "w",
                                "Database" : "w",
                                "Collection" : "w"
                        },
                        "waitingForLock" : false,
                        "lockStats" : {
                                "Global" : {
                                        "acquireCount" : {
                                                "r" : NumberLong(248109),
                                                "w" : NumberLong(248109)
                                        }
                                },
                                "Database" : {
                                        "acquireCount" : {
                                                "w" : NumberLong(248109),
                                                "W" : NumberLong(1)
                                        },
                                        "acquireWaitCount" : {
                                                "w" : NumberLong(3)
                                        },
                                        "timeAcquiringMicros" : {
                                                "w" : NumberLong(405)
                                        }
                                },
                                "Collection" : {
                                        "acquireCount" : {
                                                "w" : NumberLong(248109)
                                        }
                                }
                        }
                },

用户相关

posted @ 2022-05-23 23:42  萱乐庆foreverlove  阅读(46)  评论(0编辑  收藏  举报