当前位置:网站首页>【MongoDB】4. Usage specification of mongodb
【MongoDB】4. Usage specification of mongodb
2022-06-11 15:20:00 【ProphetMo__】
【MongoDB】4. MongoDB The standard of use
Today, I looked through the teacher's book and saw MongoDB Several usage specifications of , I think this is very helpful. Write it down first
1. Database usage specification
Databases are represented by names . You should pay attention to the following points about database naming :
- The encoding format must be UTF-8 character ;
- An empty string... Is not allowed , namely "";
- Only use ASCII Letters and numbers in the code table , Do not use underscores (_) Special characters other than ;
- Database names are case sensitive ;
- The database name length is limited to 64 Bytes ;
- The database name cannot be the same as the database name reserved by the system , namely admin、local and config database
Suggestions for database naming :
- The database name is recommended to be all lowercase
- It is not recommended to use database names starting with numbers
- The recommended database naming rule is db_xxxx, That is, the name of "see name, know meaning"
2. Collection usage specification
Collections are identified by name . The following points should be noted about the naming of collections :
- The encoding format must be UTF-8 character ;
- An empty string... Is not allowed , namely "";
- Set names cannot contain \0 character , That is, empty characters , This character represents the end of the set name ;
- Cannot appear with “System.” The beginning set name , this - Is the reserved prefix for the system collection ;
- Set naming cannot include the following characters “$”;
- The length of the set name is limited to 64 Bytes
Based on the above MongoDB Naming conventions for collections , And put forward five suggestions on collection naming from the perspective of actual development :
- It is not recommended to use anything other than _( Underline ) and .( spot ) Special characters other than ;
- It is recommended that all set names be lowercase ;
- It is not recommended to use set names starting with numbers ;
- In order to avoid the problems caused by library level lock , Try to write to a larger set using “ Single library single collection ” Structure , For new businesses, try to create new libraries , Instead of creating a new collection in an existing library ;
- The recommended set naming rule is t_xxxx;
- Use “.” To separate subsets of different namespace , For example, a blog may contain two subsets , namely blog.posts and blog.authors, and blog It doesn't exist
3. Document usage specification
The type of key in the document is generally string type , Keys can be arbitrary UTF-8 character . Note the following points about the naming of documents :
- The key in the document cannot contain “\0” character , That is, empty characters ;
- The keys in the document are prohibited from using anything except underscores “” Special characters other than , And it is not recommended to use... At the beginning "";
- It is recommended that all keys in the document be lowercase ;
- Keys in documents are not recommended to start with numbers ;
- It is not recommended to customize “_id” value
- Try to put similar documents in the same set , Scatter different types of documents in different collections , This can improve index utilization ;
- It is recommended not to store long strings , If this field is a query condition , Then make sure that the value of the field does not exceed 1KB, because MongoDB Index only supports 1KB Fields within ;
- It is recommended that if the business is insensitive to the case of stored data , Then use all uppercase / Lower case storage ( Or add an auxiliary field with uniform case );
- It is not recommended to use array fields as query criteria ;
- In the consent document , A key with the same name cannot exist ;
Excerpt from 《NoSql Database technology and application 》 Black horse programmer Huang,
边栏推荐
- Hamad application layout scheme 02 of hashicopy
- 2021 go developer survey
- Station B executives interpret the financial report: the epidemic has no impact on the company's long-term development, and the video trend is irresistible
- [mysql_11] addition, deletion and modification of data processing
- Nomad application layout scheme 04 of hashicopy (scaling and updating a job)
- 新华三交换机系统基本配置命令
- Leetcode daily question - plus one
- 数据库“百亿蓝海”中,每位玩家都能找到一叶扁舟 | C位面对面
- Tangzhengrong: CTO is the intersection of business thinking and technical thinking
- Talk about the principle of QR code scanning login
猜你喜欢

Backtracking / solution space tree permutation tree
[mysql_12] MySQL data types

19. insertion, deletion and pruning of binary search tree

B站高管解读财报:疫情对公司长期发展无影响 视频化趋势不可阻挡

【SystemVerilog 之 验证】~ 测试平台、硬件设计描述、激励发生器、监测器、比较器

Station B executives interpret the financial report: the epidemic has no impact on the company's long-term development, and the video trend is irresistible

uniapp开发微信小程序,从构建到上线

简单的C语言版本通讯录

【Azure 应用服务】NodeJS Express + MSAL 实现API应用Token认证(AAD OAuth2 idToken)的认证实验 -- passport.authenticate()

See from the minute, carve on the details: Exploration of SVG generated vector format website icon (favicon)
随机推荐
B站高管解读财报:疫情对公司长期发展无影响 视频化趋势不可阻挡
【SystemVerilog 之 接口】~ Interface
Hebei huangjinzhai scenic spot adds "AED automatic defibrillator" to ensure the life safety of tourists!
leetcode 120. 三角形最小路径和
Hashicopy之nomad应用编排方案03(运行一个job)
Small open source projects based on stm32f1
Learn more about and use ThreadLocal
[azure application service] nodejs express + msal realizes the authentication experiment of API Application token authentication (AAD oauth2 idtoken) -- passport authenticate()
[process blocks and methods of SystemVerilog] ~ domain, always process block, initial process block, function, task, life cycle
Nexus configuration Yum repository for repository manager
Hot seek tiger, a list of eco economic models
06 _ 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
3年亏损136亿,上市能救活威马吗?
2021 年 CNCF 调查:Kubernetes 跨越鸿沟的一年
Summary of redis basic knowledge
Hashicopy之nomad应用编排方案01
Hamad application layout scheme 03 of hashicopy (run a job)
04 _ 深入浅出索引(上)
Oauth2的理解
Art plus online school: Sketch common sitting posture test questions, these three angles must be mastered~