MongoDB服务下载安装
[root@3893e696a14d ~]# wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.6/x86_64/RPMS/mongodb-org-server-3.6.23-1.el7.x86_64.rpm
[root@3893e696a14d ~]# rpm -ivh mongodb-org-server-3.6.23-1.el7.x86_64.rpm
Mongodb服务的启动
[root@3893e696a14d ~]# mongod -f /etc/mongod.conf
MongoDB的操作
# 启动Mongodb客户端
[root@3893e696a14d ~]# mongo
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1fcc3160-e738-4b60-89b1-fd0f892caed0") }
MongoDB server version: 3.6.23
WARNING: shell and server versions do not match
---
....
# 查看数据库
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
test 0.000GB
# 打开指定数据库
> use test;
# 查看数据库表
# 创建数据表
>db.createCollection('teacher');
> show collections;
student
teacher
# 数据表中插入数据
> db.student.insert({'name':'lisi','age':28});
# 查看数据表数据
> db.student.find().pretty();
{
"_id" : ObjectId("60a627901c490bb040d7194e"),
"name" : "zhangsan",
"age" : 18
}
{
"_id" : ObjectId("60a627a21c490bb040d7194f"),
"name" : "lisi",
"age" : 28
}
# 删除指定数据表
> db.student.drop();
true
# 删除指定数据库
> db.dropDatabase();