当前位置:网站首页>Introduction to mongodb chapter 03 basic concepts of mongodb
Introduction to mongodb chapter 03 basic concepts of mongodb
2022-07-02 19:37:00 【Teacher Tony who doesn't cut his hair】
This article will introduce MongoDB Some basic concepts in , For example, documents 、 aggregate 、 Database and namespace .
data format
stay MongoDB in , Data usage JSON perhaps BSON Format for processing and storage .
JSON
JSON Its full name is JavaScript Object Notation, Is a lightweight data exchange format .JSON Grammar is based on JavaScript ECMA-262 3rd edition A subset of .
One JSON A document is a collection of fields and values , Follow a specific format . for example :
{
"first_name": "John",
"last_name": "Doe",
"age": 22,
"skills": ["Programming","Databases", "API"]
}
BSON
BSON representative Binary JSON, It's a kind of JSON Binary serialization of documents .BSON Pay more attention to the efficiency of storage and processing .
file
MongoDB With BSON Store data records in the form of documents , Short for document (Document).

Document is a field - A collection of values , The structure is as follows :
{
field_name1: value1,
field_name2: value2,
field_name3: value3,
...
}
In the above grammar , The field name is a string , Field values can be numbers 、 character string 、 object 、 Array etc. . for example :
{
_id: ObjectId("5f339953491024badf1138ec"),
title: "SQL Programming idea ",
isbn: "9787121421402",
publisher: " Electronic industry press ",
published_date: new Date('2021-10-01'),
author: {
first_name: " Xuyang ", last_name: " Dong "}
}
This document contains the following fields - value :
- _id It's a ObjectId;
- title Is a string ;
- isbn Is a string ;
- publisher Is a string ;
- published_date It's a Date Type data ;
- author Is an embedded document , Contains two fields : first_name and last_name.
If you know relational data , You can see that a document is like a row of records in a table , But it is more expressive than data rows .
The field names in the document need to follow the following rules :
- MongoDB Keep field _id Used to uniquely identify a document ;
- Field names cannot contain null character ;
- The outermost field name cannot be entered with $ Symbol start .
aggregate
MongoDB Use set (Colletion) Storing documents . A collection is a set of documents .

MongoDB Collections in are similar to tables in relational databases .
| MongoDB | RDBMS |
|---|---|
| file | That's ok |
| aggregate | surface |
Tables have fixed patterns ( Field definition ), But the pattern of set is dynamic . Dynamic mode means that the structure of multiple documents in the collection may be completely different . for example , The following documents can be stored in the same collection :
{
title: "SQL Programming idea ",
published_date: new Date('2021-10-01')
}
{
title: "MongoDB From entry to business practice ",
published_date: new Date('2019-09-01'),
isbn": "9787121372247"
}
The first 2 Documents than 1 Multiple documents with one field . In theory , Each document can have different fields .
A collection has a name , for example books. Collective nouns cannot contain the following :
- $ character ;
- null(\0) character ;
- An empty string ;
- With system start , because system* yes MongoDB Reserved name of internal set .
database
MongoDB The collection is stored in the database . Single MongoDB Instances can contain multiple databases (Database).

The database can be referenced by name , for example bookdb. The database name cannot be the following :
- An empty string (“”);
- Contains the following characters :/、\、.、“、*、<、>、:、|、?、$、 Space or \0( Null character );
- The length exceeds 64 byte .
MongoDB It also contains some reserved database names , for example admin、local as well as config, We cannot use these names to create new databases .
Namespace
Namespace (Namespace) It consists of the database name plus the collection name . Namespaces can be used to fully reference a collection .
for example , For the database bookdb The set in books, Namespace is bookdb.books.
边栏推荐
- 从20s优化到500ms,我用了这三招
- Virtual machine initialization script, virtual machine mutual secret key free
- 搭建哨兵模式reids、redis从节点脱离哨兵集群
- 移动机器人路径规划:人工势场法[通俗易懂]
- 450 Shenxin Mianjing 1
- checklistbox控件用法总结
- Refactoring: improving the design of existing code (Part 2)
- c语言里怎么设立优先级,细说C语言优先级
- Codeworks round 802 (Div. 2) pure supplementary questions
- AcWing 1137. Select the best line solution (the shortest circuit)
猜你喜欢

xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

Data dimensionality reduction factor analysis

Usage of ieda refactor

字典

机器学习笔记 - 时间序列预测研究:法国香槟的月销量

IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config

安装单机redis详细教程

《重构:改善既有代码的设计》读书笔记(上)

线程应用实例
![[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)](/img/c1/a00425f2e1824a50644c8fbb15fe38.jpg)
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
随机推荐
450 Shenxin Mianjing 1
嵌入式(PLD) 系列,EPF10K50RC240-3N 可编程逻辑器件
AcWing 1125. 牛的旅行 题解(最短路、直径)
Watchful pioneer world outlook Architecture - (how does a good game come from)
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
4274. 后缀表达式-二叉表达式树
Chapter 7 - class foundation
AcWing 1134. 最短路计数 题解(最短路)
搭建哨兵模式reids、redis从节点脱离哨兵集群
Implementation of 452 strcpy, strcat, StrCmp, strstr, strchr
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
Introduction of Ethernet PHY layer chip lan8720a
What is the MySQL backup suffix_ MySQL backup restore
[ERP software] what are the dangers of the secondary development of ERP system?
golang:[]byte转string
Zabbix5 client installation and configuration
451-memcpy、memmove、memset的实现
A4988 drive stepper motor "recommended collection"
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5