56 lines
1.5 KiB
Markdown
56 lines
1.5 KiB
Markdown
|
# 离线安装
|
||
|
https://www.mongodb.com/try/download/community
|
||
|
## 下载
|
||
|
```shell
|
||
|
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.25.tgz
|
||
|
```
|
||
|
## 解压
|
||
|
```shell
|
||
|
tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.2.25.tgz
|
||
|
```
|
||
|
## 配置环境变量
|
||
|
```shell
|
||
|
# mongodb-install-directory 换为解压位置
|
||
|
# sudo cp <mongodb-install-directory>/bin/* /usr/local/bin/
|
||
|
sudo cp mongodb-linux-x86_64-ubuntu1804-4.2.25/bin/* /usr/local/bin/
|
||
|
```
|
||
|
|
||
|
## 启动
|
||
|
```shell
|
||
|
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
|
||
|
# 报错
|
||
|
mongod: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
|
||
|
# 全局查找文件
|
||
|
find / -name 'libssl.so.1.1'
|
||
|
# 复制到使用位置
|
||
|
cp /snap/core18/2812/usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/libssl.so.1.1
|
||
|
tail -f /var/log/mongodb/mongod.log
|
||
|
waiting for connections on port 27017
|
||
|
```
|
||
|
|
||
|
|
||
|
|
||
|
```
|
||
|
# 查看数据库
|
||
|
show dbs;
|
||
|
# 创建切换数据库
|
||
|
use testdb;
|
||
|
# 先创建集合,类似数据库中的表
|
||
|
db.createCollection("testtab")
|
||
|
# 查看集合表
|
||
|
show tables
|
||
|
# 插入数据
|
||
|
db.testdb.insertOne({"name":"菜鸟教程"})
|
||
|
|
||
|
db.testtab.insert({title: 'MongoDB 教程',
|
||
|
description: 'MongoDB 是一个 Nosql 数据库',
|
||
|
by: '教程',
|
||
|
url: 'http://www.baidu.com',
|
||
|
tags: ['mongodb', 'database', 'NoSQL'],
|
||
|
likes: 100
|
||
|
})
|
||
|
# 查看信息
|
||
|
db.testtab.find()
|
||
|
# 修改
|
||
|
db.testtab.update({'title':'MongoDB 教程'},{$set:{'title':'MongoDB MongoDB'}})
|
||
|
```
|