Linux安装

官网下载红帽安装版

#下载三个rpm包
wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-tools-4.2.8-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-server-4.2.8-1.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-shell-4.2.8-1.el7.x86_64.rpm

然后安装

#安装包
sudo rpm -ivh mongodb-org-server-4.2.8-1.el7.x86_64.rpm
sudo rpm -ivh mongodb-org-shell-4.2.8-1.el7.x86_64.rpm
sudo rpm -ivh mongodb-org-tools-4.2.8-1.el7.x86_64.rpm

更改配置的IP绑定,使其支持远程访问

# 修改配置文件,这样就可以远程连接
sudo vi /etc/mongod.conf # 把bindIp: 127.0.0.1改成 bindIp: 0.0.0.0

相关的服务命令:

# 启动服务
service mongod start # 关闭服务
service mongod stop # 重启服务
service mongod restart # 设置开机自启动
systemctl enable mongod.service

命令操作:

登陆mongoDB

# 登陆本机实例
mongo # 或者登陆远程实例
mongo --host=centos7-03 --port=27017

登陆成功展示mongoDB实例的信息:

[root@centos7-02 mongo-db]# mongo
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e581b090-f450-4a25-acef-93ddbd85d630") }
MongoDB server version: 4.2.8
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2022-02-02T13:05:37.482+0800 I CONTROL [initandlisten]
2022-02-02T13:05:37.482+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2022-02-02T13:05:37.482+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2022-02-02T13:05:37.482+0800 I CONTROL [initandlisten]
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten]
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten]
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2022-02-02T13:05:37.483+0800 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
--- >

一、库操作:

查看实例中已经持久化的所有库:

# show dbs
# show databases #########################################
> show dbs
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB #########################################
> show databases
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB

默认库:

admin:
从权限的角度来看,这是"root"数据库。
要是将一个用户添加到这个数据库,这个用户自动继承所有数据库的权限。
一些特定的服务器端命令也只能从这个数据库运行,比如列出所有的数据库或者关闭服务器。
local:
这个数据永远不会被复制,可以用来存储限于本地单台服务器的任意集合
config:
当Mongo用于分片设置时,config数据库在内部使用,用于保存分片的相关信息

切换库  use '库名' ,如果库不存在则创建该库并切换

> use db-03
switched to db db-03

库名的一些声明规范

# 数据库名称设置要求
- 不能是空字符串("")。
- 不得含有' '(空格)、.、$、/、\和\0 (空字符)。
- 应全部小写。
- 最多64字节。

这个库还只存在于内存中,因为库里没有任何表(集合),没有任何存储的数据

mongoDB就不会持久化到硬盘中,如何证明?

再次查询所有库,会发现切换的db-03库在列表中不存在

> show dbs
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB

删除当前正在使用的数据库(持久化了的才有效):

db.dropDatabase()

刚刚的db-03只存在与内存中,未持久化,执行不会影响

> use db-03
switched to db db-03

> show dbs
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB

> db.dropDatabase()
{ "ok" : 1 }

> show dbs
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB

如果是持久的db-01,则会被删除

> show dbs
admin 0.000GB
config 0.000GB
db-01 0.000GB
local 0.000GB
> use db-01
switched to db db-01
> db.dropDatabase()
{ "dropped" : "db-01", "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB

修改库名:

MongDB没有直接修改库名的操作

可以借助集合改名或者创建新库持久化后,删除原库实现

https://blog.csdn.net/chandoudeyuyi/article/details/80038743

二、集合(表)操作

> db.createCollection('table-01')
{ "ok" : 1 }

查看当前库下所有的集合

# show collections
# show tables > show collections
table-01
> show tables
table-01

集合命名规范:

集合名不能是空字符串""。
集合名不能含有\0字符(空字符),这个字符表示集合名的结尾。
集合名不能以"system."开头,这是为系统集合保留的前缀。
用户创建的集合名字不能含有保留字符。有些驱动程序的确支持在集合名里面包含,这是因为某些系统生成的集合中包含该字符。除
非你要访问这种系统创建的集合,否则千万不要在名字里出现$。

默认集合创建:

当向一个集合中插入一个文档的时候,如果集合不存在,则会自动创建集合。
提示:通常我们使用隐式创建文档即可。

删除集合

# 一般删除
db.集合名.drop() # 特殊字符删除
db.getCollection("集合名").drop(); ##########################
> db.getCollection('table-03').drop();
true
> db.getCollection('table-03').drop();
false # 特殊字符使用这种删除会报错
> db.table-03.drop()
2022-02-02T14:24:24.124+0800 E QUERY [js] uncaught exception: TypeError: 3.drop is not a function :
@(shell):1:10
 
 

【MongoDB】Re01 安装与基础操作的更多相关文章

  1. mysql二进制安装及基础操作

    mysql二进制安装及基础操作 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    mysql-5.6.36-linux-glibc2.5-x86_64 1.安装 采用二进 ...

  2. MongoDB的安装与python操作MongoDB

    一.安装MongoDB 因为我个人使用的是windows,就只记录下windows下的安装 1.下载安装 就是官网,下载msi,选个路径安装 2.配置 看见别的地方说需要手动在bin同级目录创建dat ...

  3. 项目实战12.1—企业级监控工具应用实战-zabbix安装与基础操作

    无监控,不运维.好了,废话不多说,下面都是干货. 警告:流量党勿入,图片太多!!! 项目实战系列,总架构图 http://www.cnblogs.com/along21/p/8000812.html ...

  4. mongodb的安装与简单操作

    MongoDB中文社区:http://www.mongoing.com     数据库的使用场景 SQL(关系型数据库):MySQL.SQLServer  --->磁盘操作 1.高度事务性的场景 ...

  5. Kafka 教程(二)-安装与基础操作

    单机安装 1. 安装 java 2. 安装 zookeeper [这一步可以没有,因为 kafka 自带了 zookeeper] 3. 安装 kafka 下载链接 kafka kafka 是 scal ...

  6. win下的mongodb安装和基础操作

    一.下载地址: https://www.mongodb.com/download-center/community 二.安装错误: 1.安装过程中报错(类似下图): 原因:没有管理员权限 解决:管理员 ...

  7. MongoDB的安装及CURD操作

    MongoDB的下载地址:http://www.mongodb.org/downloads MongoDB有32bit和64bit两个版本,32bit只能存放2GB数据.我们选择64bit版进行下载. ...

  8. mongodb数据库安装及常见操作

    客户端和服务端的安装 # rpm -ivh mongo-10gen-2.4.6-mongodb_1.x86_64.rpm mongo-10gen-server-2.4.6-mongodb_1.x86_ ...

  9. mongodb的安装和sql操作

    mongodb安装环境:centos6.5https://www.mongodb.org/dl/linux/x86_64wget https://fastdl.mongodb.org/linux/mo ...

  10. redis安装及基础操作(1)

    ============================================================= 编译安装 0.环境 Linux:centos6.5 redis:3.0.5 ...

随机推荐

  1. bash: _get_comp_words_by_ref: command not found 报错

    没有安装补全的包 错误信息 bash: _get_comp_words_by_ref: command not found 表明你的 shell 中可能存在补全功能的问题. 通常,这种错误发生在你的系 ...

  2. 阿里bxet逆向

    声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除! 目标网站 x82y 分析过 ...

  3. kettle从入门到精通 第十七课 kettle Transformation executor

    Transformation executor步骤是一个流程控件,和映射控件类似却又不一样. 1.子转换需要配合使用从结果获取记录和复制记录到结果两个步骤,而子映射需要配合映射输入规范和映射输出规范使 ...

  4. java对列表分页的方法,及mysql分页的sql原型

    java对列表分页的方法,及mysql分页的sql原型 1.mysql * mysql分页查询: * select <include refid="Base_Column_List&q ...

  5. hdu 5072 coprime不完整题解

    Problem Description There are n people standing in a line. Each of them has a unique id number. Now ...

  6. .NET使用CsvHelper快速读取和写入CSV文件

    前言 在日常开发中使用CSV文件进行数据导入和导出.数据交换是非常常见的需求,今天我们来讲讲在.NET中如何使用CsvHelper这个开源库快速实现CSV文件读取和写入. CsvHelper类库介绍 ...

  7. 采集modbus设备数据转wincc项目案例

    1         文档说明 1.   网关设置采集Modbus设备数据 2.   把采集的数据转成profinet协议转发给wincc. 2         VFBOX网关工作原理 VFBOX网关是 ...

  8. Django-缓存、信号与序列化

    缓存 1.缓存的简介 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次的的后台操作 ...

  9. Lfu缓存在Rust中的实现及源码解析

    一个 lfu(least frequently used/最不经常使用页置换算法 ) 缓存的实现,其核心思想是淘汰一段时间内被访问次数最少的数据项.与LRU(最近最少使用)算法不同,LFU更侧重于数据 ...

  10. Zynq 7000的3种IO

    概念 MIO MIO:多功能IO接口(分配在 GPIO 的 Bank0 和Bank1),属于Zynq的PS部分,在芯片外部有54个引脚.这些引脚可以用在GPIO.SPI.UART.TIMER.Ethe ...