下载地址
https://www.mongodb.com/try/download/community
二、Linux上安装mongdb
23-MongoDB介绍、安装、使用 - 【二、Linux安装mongdb】
https://www.yuque.com/laibeikafei-ptsot/sp4xmo/otorbr
三、Windows上安装mongdb
https://www.cnblogs.com/TM0831/p/10606624.html
netstat -lanp | grep “27017”
设置密码
use pos
db.createUser({
user: 'root',
pwd: 'root',
roles:[{
role: 'readWrite',
db: 'pos'
}]
})
show users # 查看所有用户信息
============
下载mongodb软件及mongodb-shell
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.2.tgz
wget https://downloads.mongodb.com/compass/mongosh-1.6.0-linux-x64.tgz
tar -xvf mongodb-linux-x86_64-rhel80-6.0.2.tgz
mv mongodb-linux-x86_64-rhel80-6.0.2 /usr/local/mongodb
4、编辑配置文件
mkdir -p /data/mongodb
vim /data/mongodb/mongodb.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/mongodb.log
storage:
dbPath: /data/mongodb
journal:
enabled: true
processManagement:
fork: true
net:
port: 27017
bindIp: 0.0.0.0
5、启动与检查
/usr/local/mongodb/bin/mongod -f /data/mongodb/mongodb.conf
ls /data/mongodb
ps -aux | grep mongo
netstat -antup | grep mongo
三、基本命令
use mydb
db.myuser.insertOne({ name: 'john', age:28 })
show dbs
show collections
1、mongodb创建库、创建集合、插入数据
use mydb
db.myuser.insertOne({ name: 'john', age:28 })
show dbs
show collections
db.myuser.insertOne( {'name': 'jerry', age: 27} )
db.myuser.insertOne( {'name': 'mary', age: 26} )
db.myuser.find()
db.myuser.find( { name: 'john' } )
db.myuser.find( { age: 26 } )
[root@hadoop07 bin]# pwd
/home/software/mongosh/bin
[root@hadoop07 bin]# mongod -f /data/mongodb/mongodb.conf
[root@hadoop07 bin]# pwd
/home/software/mongosh/bin
[root@hadoop07 bin]# ./mongosh
db.shutdownServer()
show users // 查看当前库下的用户
db.dropUser('testadmin') // 删除用户
db.updateUser('admin', {pwd: '654321'}) // 修改用户密码
db.auth('admin', '654321') // 密码认证