当前位置:网站首页>Introduction, installation and basic use of mongodb database
Introduction, installation and basic use of mongodb database
2022-07-21 02:37:00 【@Wei dada】
List of articles
MongoDB Database introduction 、 Installation and basic use
One 、 Preface
1.1 Introduction to basic concepts
We are in the process of learning , Access to a large number of databases , for example Sql Server
、Mysql
、Mybatis
etc. , They all belong to traditional relational databases , That is, data based on two-dimensional table .
What we learn today is MongoDB
Database is not a traditional relational database , It is between relational database and non relational database , Yes no relational database has the most functions , Most like a relational database NoSQL(Not Only Sql)
database , With key-value
stored , Do not follow the basic requirements of traditional relational databases 、 Table structure and other features .
NoSQL
It is mainly used to help solve big data query problems , It is of great significance in the era of big data .
1.2 Nosql Compared with relational databases
Unstructured database has no rows 、 The concept of column , Use JSON
Store the data , aggregate Equivalent to... In a relational database surface , The document is equivalent to That's ok .
Two 、 install
2.1 download
visit MongoDB
Official website :www.mongodb.com Download it , Here is the download link of community version https://www.mongodb.com/try/download/community.
Pay attention to choosing the correct version 、 Platforms and packages , Here is the download 5.0.9
edition 、Windows
platform 、MSI
Installation package .
Foreign websites are not necessarily easy to download , The following is what I uploaded CSDN
resources ( free ):
2.2 install
- Double click Install Package
- All the way to the next step
- Custom installation
- Select installation location
- Select the data storage location ( It is recommended to choose a disk with large space )
- Don't choose to install
MongoDB Compass
( If the network is bad, the download will fail , You can install it later )
- Click on the install
2.4 environment variable
- Copy
MongoDB
Ofbin
Path to directory , I am here :D:MongoDb\bin
- Right click on the left side of the folder “ This computer ”, choice “ attribute ”: This computer
->
attribute
- Create a new environment variable
- Open terminal input :
mongo
, The output is as follows ( It could be different , I am here5.0.8
edition )
PS E:\Code> mongo
MongoDB shell version v5.0.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session {
"id" : UUID("bdfd1afc-e66b-4211-bf91-16e80d6845d5") }
MongoDB server version: 5.0.8
================
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.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting:
2022-07-16T07:08:30.841+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()
---
>
3、 ... and 、 Easy to use
First, enter... At the terminal mongo
Establish a database connection , The command can be executed later ! Be careful , The following commands are continuous , Suggest sequential learning .
3.1 show dbs
view the database , Just installed MongoDB
There will be three basic databases , Don't delete them , as follows :
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
3.2 use db_name
Selecting a database you want to operate requires use db_name
Instructions
> use db_posts
switched to db db_posts
Be careful :
Here you can choose a nonexistent database , If so, it can be used to create a new database .
But at this time, the database has not been created , You need to insert data before creating a database .
3.3 insert()
insert()
Method is used to insert data into the specified set , for example :
> db.user.insert({
username:' Xiao Ming ',age:12})
WriteResult({
"nInserted" : 1 })
Be careful :
The database cannot insert data directly , You need to aggregate Insert data ( file ), there
user
It's just a set .If
user
If it doesn't exist, a new one will be createduser
surface , The format of data insertion is standardJSON
Format .
At this time, a new database is created db_posts
And a new user table user
, And insert a data into the table . If we use show dbs
You can see the database db_posts
了 .
> show dbs
admin 0.000GB
config 0.000GB
db_posts 0.000GB
local 0.000GB
3.4 show collections
Check how many tables are in the current database ( aggregate ) Need to use show collections
command :
> show collections
user
3.5 find()
Use db. Table name .find()
You can query all the data in the table :
> db.user.find()
{
"_id" : ObjectId("62d285cbb9789c8ce412e785"), "username" : " Xiao Ming ", "age" : 12 }
We can insert a few more pieces of data :
> db.user.insert({
username:' Xiaohong ',age:99})
WriteResult({
"nInserted" : 1 })
> db.user.insert({
username:' cockroach ',age:999})
WriteResult({
"nInserted" : 1 })
> db.user.find()
{
"_id" : ObjectId("62d285cbb9789c8ce412e785"), "username" : " Xiao Ming ", "age" : 12 }
{
"_id" : ObjectId("62d28835b9789c8ce412e786"), "username" : " Xiaohong ", "age" : 99 }
{
"_id" : ObjectId("62d2884cb9789c8ce412e787"), "username" : " cockroach ", "age" : 999 }
3.6 drop()
Deleting a collection requires db. Table name .drop()
:
> db.user.drop()
true
> show collections
>
3.7 dropDatabase()
Delete database , There is an embarrassing place here , Databases without collections are not displayed , That is to say, in the implementation of dropDatabase
The database was no longer visible . Anyway, this syntax is to delete the database , Don't care about these details .
> db.dropDatabase()
{
"ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
边栏推荐
- excel怎么选取特定数字求和?excel选中特定数字求和的方法
- 返回日期对应的一年中的第几周
- 返回给定日期月份中最后一个日期的字符串表示形式
- 元宇宙 3D 开荒场
- How do independent website sellers use Facebook homepage for social media marketing?
- 有奖调研 | 让虚拟照入现实的完美AR开发平台长什么样?
- Difi: a go as you pay Wi Fi access system intensive reading notes (III)
- 【MUDUO 日志系统2】Timestamp时间
- 开发者必读:2022年移动应用运营增长洞察白皮书
- 青海vr消防模拟演练系统,满足了对多人群多场景下的培训需求
猜你喜欢
得物App数据模拟平台的探索和实践
得物客服一站式工作台卡顿优化之路
Category loss and location loss of target detection
Apache Flink 的 Per-Job 提交流程
NFT fashion shoes ar interactive zero foundation tutorial is coming!
The beta version of typera is expired and cannot be used normally
Structure completion (flexible array)
Apache Flink 的 YARN Session 提交流程
织梦添加栏目修改栏目时提示“保存目录数据时失败,请检查你的输入资料是否存在问题”
Redis application
随机推荐
图解LeetCode——731. 我的日程安排表 II(难度:中等)
Qinghai VR fire simulation drill system meets the training needs of many people and scenes
Inserting data in stored procedures and for loops
Category loss and location loss of target detection
Per job submission process of Apache Flink
集成 WebSocket 发送消息到客户端
织梦添加栏目修改栏目时提示“保存目录数据时失败,请检查你的输入资料是否存在问题”
Analysis on the wallet system architecture of Baidu trading platform
请别再使用 SimpleDateFormat 格式化时间了,DateTimeFormatter 更出色!
买量洞察与渠道评估,助力营销决策优化
Design of special classes (singleton mode)
The beta version of typera is expired and cannot be used normally
[Android开发学iOS系列] 语言篇: Swift vs Kotlin
Excel管理Simulink SWC中的标定量与观测量之标定量
Software interface and simple system simulation
cnvd_2019_22238
【SELECT、POLL的缺点,以及EPOLL的优势】
从对象中获取一年中的日期(范围 1-366 中的数字)Date
爱学啊的博客-人生苦短,只做好课!
从概念到安全实践:软件供应链基础指南