【MongoDB】Re01 安装与基础操作
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 安装与基础操作的更多相关文章
- mysql二进制安装及基础操作
mysql二进制安装及基础操作 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 mysql-5.6.36-linux-glibc2.5-x86_64 1.安装 采用二进 ...
- MongoDB的安装与python操作MongoDB
一.安装MongoDB 因为我个人使用的是windows,就只记录下windows下的安装 1.下载安装 就是官网,下载msi,选个路径安装 2.配置 看见别的地方说需要手动在bin同级目录创建dat ...
- 项目实战12.1—企业级监控工具应用实战-zabbix安装与基础操作
无监控,不运维.好了,废话不多说,下面都是干货. 警告:流量党勿入,图片太多!!! 项目实战系列,总架构图 http://www.cnblogs.com/along21/p/8000812.html ...
- mongodb的安装与简单操作
MongoDB中文社区:http://www.mongoing.com 数据库的使用场景 SQL(关系型数据库):MySQL.SQLServer --->磁盘操作 1.高度事务性的场景 ...
- Kafka 教程(二)-安装与基础操作
单机安装 1. 安装 java 2. 安装 zookeeper [这一步可以没有,因为 kafka 自带了 zookeeper] 3. 安装 kafka 下载链接 kafka kafka 是 scal ...
- win下的mongodb安装和基础操作
一.下载地址: https://www.mongodb.com/download-center/community 二.安装错误: 1.安装过程中报错(类似下图): 原因:没有管理员权限 解决:管理员 ...
- MongoDB的安装及CURD操作
MongoDB的下载地址:http://www.mongodb.org/downloads MongoDB有32bit和64bit两个版本,32bit只能存放2GB数据.我们选择64bit版进行下载. ...
- mongodb数据库安装及常见操作
客户端和服务端的安装 # rpm -ivh mongo-10gen-2.4.6-mongodb_1.x86_64.rpm mongo-10gen-server-2.4.6-mongodb_1.x86_ ...
- mongodb的安装和sql操作
mongodb安装环境:centos6.5https://www.mongodb.org/dl/linux/x86_64wget https://fastdl.mongodb.org/linux/mo ...
- redis安装及基础操作(1)
============================================================= 编译安装 0.环境 Linux:centos6.5 redis:3.0.5 ...
随机推荐
- LeetCode 332. Reconstruct Itinerary重新安排行程 (C++/Java)
题目: Given a list of airline tickets represented by pairs of departure and arrival airports [from, to ...
- INFINI Labs 产品更新 | Console 告警中心 UI 全新改版,新增 Dashboard 全屏模式等功能
本次 INFINI Labs 产品更新主要发布 Console v1.7.0,重点优化了 Console 告警中心和数据看板 Dashboard 可视化功能.详细介绍如下: 优化告警中心 UI 上个版 ...
- LINQ to Entities does not recognize the method 'System.String ToString()' method
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method ca ...
- Vector + ClickHouse 收集日志
目前业界的日志生态,最常用的是 ELK,其次就是 ClickHouse,本文会演示如何使用 Vector + ClickHouse 来采集 Nginx 日志并做清洗,最终写入 ClickHouse.至 ...
- Java编码规范-字符串与Integer的比较,BigDecimal非空参数
Java编码规范-字符串与Integer的比较,BigDecimal非空参数 package com.example.core.mydemo; import java.math.BigDecimal; ...
- Java代码忽略https证书:解决No subject alternative names present问题 HttpURLConnection https请求
Java代码忽略https证书:解决No subject alternative names present问题 import org.slf4j.Logger; import org.slf4j.L ...
- 天翼云安装nexus3.37.1
有点操蛋,官网网络太慢了! 百度了不少网友的内容,综合如下 总体是个皮毛,但已经可以用于开发了! 一.下载和安装 https://download.sonatype.com/nexus/3/nexus ...
- 格式化显示JSON数据
测试JSON {"took":1,"timed_out":false,"_shards":{"total":1,&quo ...
- 化合物同位素理论同位素分布计算软件Isopro 3.0
大家好,今天分享一款软件,即可以计算化合物理论同位素分布的软件Isopro 3.0.在做质谱的实验时,特别对合成的化合物进行质量表征时,往往要求ppm绝对值在5以内,对质谱的分辨率要求很高.对于小分子 ...
- python基础-内置函数
# callable() # 函数用于检查一个对象是否是可调用的.如果返回 True,object 仍然可能调用失败:但如果返回 False,调用对象 object 绝对不会成功. # 对于函数.方法 ...