Date Tags MongoDB

MacOS安装Mongo

  1. 官方网站下载对一个Mac安装包
  2. 解压到本地目录下
  3. 创建一个配置文件,例如 /etc/mongod.conf , set the dbpath to your preferred path.

    # This is an example config file for MongoDB.
    dbpath = /var/lib/mongodb
    bind_ip = 127.0.0.1
    noauth = true # use 'true' for options that don't take an argument
    verbose = true # to disable, comment out.
    
  4. 启动 mongo, mongod --config /etc/mongod.conf

备份和恢复

备份:

mongodump --host HOSTNAME -port 27071 --username USER_NAME --password PASSWORD -d DB_NAME -o /tmp/dump/mongo/

恢复:

mongorestore --host HOSTNAME -port 27071 --username USER_NAME --password PASSWORD -d DB_NAME --drop /tmp/dump/mongo/

控制台基本命令操作

  • db.collection.find()
  • db.collection.update({name:'www'},{$set{col1:'xxxx'}},false, true)
  • db.collection.remove()
  • db.auth('userid', 'pass')