MongoDb

MongoDb

什么是mongodb?

MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。
MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成。

在mongodb中数据库对应mysql的数据库,集合对应mysql的表,可以这样理解

搭建mongodb环境

下载地址:https://www.mongodb.com/download-center/community
安装完成之后,直接在安装路径下面找到bin里面的mongo.exe,直接执行
出现如图便是成功的
在这里插入图片描述
可以执行简单的操作命令试一试,show databases 显示所有数据
在这里插入图片描述
mongodb常见的指令:
use DATABASE_NAME 创建数据库,数据库不存在直接创建
db.runoob.insert(json数据) 插入语数据
show collections 展示数据库下面的集合
db.createCollection(集合的名字)
db.collection.drop() 删除集合
use 数据库名字 表示准备使用那一个数据库,切换数据库也是这样的操作
db.collection.find({}) 查询所有

MongoDB shell version v5.0.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2c19d0a5-a60f-478f-a64f-48533f0abfb7") }
MongoDB server version: 5.0.2
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting:
        2021-09-15T22:50:18.350+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        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 database
uncaught exception: Error: don't know how to show [database] :
shellHelper.show@src/mongo/shell/utils.js:1211:11
shellHelper@src/mongo/shell/utils.js:838:15
@(shellhelp2):1:1
> show databases
admin   0.000GB
config  0.000GB
local   0.000GB
> db.rrrr.insert({"aaa":1})
WriteResult({ "nInserted" : 1 })
> show databases
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB
> use test
switched to db test
> show collesctions
uncaught exception: Error: don't know how to show [collesctions] :
shellHelper.show@src/mongo/shell/utils.js:1211:11
shellHelper@src/mongo/shell/utils.js:838:15
@(shellhelp2):1:1
> show collections
rrrr
> db.createCollection("name")
{ "ok" : 1 }
> show collections
name
rrrr
> db.rrrr.drop()
true
> show collections
name
> use admin
switched to db admin
> show collections
system.version
>



mongodb使用条件

  1. 数据量超过亿级并且还要不断的扩容
  2. 每秒2000-3000的读写
  3. 数据莫名多种多样,来源多
  4. 大型地理位置的使用 (这个大公司使用的多)
  5. 系统快速写入,低延迟
  6. 集合之间的关系不要太复杂

mongodb使用场景

  1. 日志收集
  2. lot设备
  3. 数据爬虫
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小盆友你是否很有多问号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值