MongoDB 2.6.9的安装

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10  
echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list  
sudo apt-get update  
sudo apt-get install -y mongodb-org=2.6.9 mongodb-org-server=2.6.9 mongodb-org-shell=2.6.9 mongodb-org-mongos=2.6.9 mongodb-org-tools=2.6.9  

MongoDB 3.2

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv EA312927  
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list  
sudo apt-get update  
sudo apt-get install -y mongodb-org

官方文档地址:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

基本测试:
直接输入mongo看一看,缺省是连到test库去了

增加用户基本操作:

进入mongo命令行:
$ mongo

建立explorerdb库:
> use explorerdb

建立一个可以读写explorerdb库的用户:
> db.createUser( { user: "explorer", pwd: "3xp!0reR", roles: [ "readWrite" ] } )
注意:如果用的是 mongo shell 2.4.x, 命令是addUser而不是createUser
> db.addUser( { user: "username", pwd: "password", roles: [ "readWrite"] })

删除库
mongo  
use explorerdb  
show collections  
db.collectionName.find()  
db.collectionName.remove({}) db.collectionName.drop()  
comments powered by Disqus