MongoDB concept Attentions

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介:
1. Every document has a special key, "_id",  that  is unique across  the document's collection.

2. Key/value pairs in documents are ordered.
{"foo" : 3, "greeting" : "Hello, world!"} 
{"greeting" : "Hello, world!", "foo" : 3}
这两条document不相同.

3. The keys in a document are strings. Any UTF-8 character is allowed in a key, with a
few notable exceptions:
3.1 Keys must not contain the character \0 (the null character). This character is used
to signify the end of a key.
3.2 The . and $ characters have some special properties and should be used only in
certain circumstances, as described  in  later chapters.  In general,  they should be
considered reserved, and drivers will complain if they are used inappropriately.
3.3 Keys starting with _ should be considered reserved; although  this  is not strictly
enforced.
3.4 MongoDB is type-sensitive and case-sensitive. For example, these documents are
distinct:
{"foo" : 3}
{"foo" : "3"}
As are as these:
{"foo" : 3}
{"Foo" : 3}

4. A final important thing to note is that documents in MongoDB cannot contain duplicate
keys. For example, the following is not a legal document:
{"greeting" : "Hello, world!", "greeting" : "Hello, MongoDB!"}

5. Collections are schema-free. This means that the documents within a single collection
can have any number of different “shapes.” 
For example, both of the following documents could be stored in a single collection:
{"greeting" : "Hello, world!"}
{"foo" : 5}

6. Note that the previous documents not only have different types for their values (string
versus integer) but also have entirely different keys. Because any document can be put
into any collection, the question often arises: “Why do we need separate collections at
all?” It’s a good question—with no need  for separate schemas  for different kinds of
documents, why  should we  use more  than  one  collection?  There  are  several  good
reasons:
6.1 Keeping different kinds of documents in the same collection can be a nightmare
for developers and admins. Developers need to make sure that each query is only
returning documents of a certain kind or that the application code performing a
query can handle documents of different shapes. If we’re querying for blog posts,
it’s a hassle to weed out documents containing author data.
6.2 It is much faster to get a list of collections than to extract a list of the types in a
collection. For example, if we had a type key in the collection that said whether
each document was a “skim,” “whole,” or “chunky monkey” document, it would
be much slower to find those three values in a single collection than to have three
separate collections and query for their names (see  “Subcollections”
on page 8).
6.3 Grouping documents of the same kind together in the same collection allows for
data locality. Getting several blog posts from a collection containing only posts will
likely require fewer disk seeks than getting the same posts from a collection con-
taining posts and author data.
6.4 We begin to impose some structure on our documents when we create indexes.
(This is especially true in the case of unique indexes.) These indexes are defined
per collection. By putting only documents of a single type into the same collection,
we can index our collections more efficiently.
  As you can see, there are sound reasons for creating a schema and for grouping related
types of documents together. MongoDB just relaxes this requirement and allows de-
velopers more flexibility.

7. Naming
A collection is identified by its name. Collection names can be any UTF-8 string, with
a few restrictions:
7.1 The empty string ("") is not a valid collection name.
7.2 Collection names may not contain the character \0 (the null character) because
this delineates the end of a collection name.
7.3 You should not create any collections that start with system., a prefix reserved for
system collections. For example, the  system.users collection contains the database’s
users, and the system.namespaces collection contains information about all of the
database’s collections.
7.4 User-created collections should not contain the reserved character $ in the name.
The various drivers available for the database do support using $ in collection
names because some system-generated collections contain it. You should not use
$ in a name unless you are accessing one of these collections.

8. Subcollections
One convention for organizing collections is to use namespaced subcollections sepa-
rated by the . character. For example, an application containing a blog might have a
collection named blog.posts and a separate collection named blog.authors. This is for
organizational purposes only—there is no relationship between the blog collection (it
doesn’t even have to exist) and its “children.”
Although subcollections do not have any special properties, they are useful and incor-
porated into many MongoDB tools:
8.1 GridFS, a protocol for storing large files, uses subcollections to store file metadata
separately from content chunks 
8.2 The MongoDB web console organizes the data in its DBTOP section by
subcollection 
8.3 Most drivers provide some syntactic sugar for accessing a subcollection of a given
collection. For example, in the database shell, db.blog will give you the blog col-
lection, and db.blog.posts will give you the blog.posts collection.
  Subcollections are a great way to organize data in MongoDB, and their use is highly
recommended.
有点类似PostgreSQL中,表继承的概念.

9. Databases
In addition to grouping documents by collection, MongoDB groups collections  into
databases. A single instance of MongoDB can host several databases, each of which can
be thought of as completely independent. A database has its own permissions, and each
database is stored in separate files on disk. A good rule of thumb is to store all data for
a single application in the same database. Separate databases are useful when storing
data for several application or users on the same MongoDB server.
Like collections, databases are identified by name. Database names can be any UTF-8
string, with the following restrictions:
9.1 The empty string ("") is not a valid database name.
9.2 A database name cannot contain any of these characters: ' ' (a single space), ., $, /,
\, or \0 (the null character).
9.3 Database names should be all lowercase.
9.4 Database names are limited to a maximum of 64 bytes.
One thing to remember about database names is that they will actually end up as files
on your filesystem. This explains why many of the previous restrictions exist in the first
place.
9.5 There are also several reserved database names, which you can access directly but have
special semantics. These are as follows:
admin
This  is the “root” database,  in terms of authentication. If a user  is added to the
admin database, the user automatically inherits permissions for all databases.
There are also certain server-wide commands that can be run only from the ad-
min database, such as listing all of the databases or shutting down the server.
local
This database will never be replicated and can be used to store any collections that
should be local to a single server .
config
When Mongo is being used in a sharded setup , the config database
is used internally to store information about the shards.
By prepending a collection’s name with its containing database, you can get a fully
qualified collection name called a  namespace.  For  instance,  if  you  are  using  the
blog.posts collection in the cms database, the namespace of that collection would be
cms.blog.posts. Namespaces are limited to 121 bytes in length and, in practice, should
be less than 100 bytes long.
目录
相关文章
|
Web App开发 安全 Java
SpringBoot开发案例之集成SSL证书
SSL简介 SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议。
13689 0
|
10月前
|
机器学习/深度学习 人工智能 达摩院
MVGenMaster:复旦联合阿里等实验室推出的多视图扩散模型
MVGenMaster是由复旦大学、阿里巴巴达摩院和湖潘实验室联合推出的多视图扩散模型,专注于新视角合成(NVS)任务。该模型通过整合3D先验信息,显著提升了NVS的泛化和3D一致性,并能从单一图像生成多达100个新视图。此外,研究团队还推出了包含160万场景的大型多视图图像数据集MvD-1M,以支持模型的训练和优化。
232 27
MVGenMaster:复旦联合阿里等实验室推出的多视图扩散模型
|
10月前
|
人工智能 运维 监控
阿里云ACK容器服务生产级可观测体系建设实践
本文整理自2024云栖大会冯诗淳(花名:行疾)的演讲,介绍了阿里云容器服务团队在生产级可观测体系建设方面的实践。冯诗淳详细阐述了容器化架构带来的挑战及解决方案,强调了可观测性对于构建稳健运维体系的重要性。文中提到,阿里云作为亚洲唯一蝉联全球领导者的容器管理平台,其可观测能力在多项关键评测中表现优异,支持AI、容器网络、存储等多个场景的高级容器可观测能力。此外,还介绍了阿里云容器服务在多云管理、成本优化等方面的最新进展,以及即将推出的ACK AI助手2.0,旨在通过智能引擎和专家诊断经验,简化异常数据查找,缩短故障响应时间。
阿里云ACK容器服务生产级可观测体系建设实践
|
10月前
|
人工智能 并行计算 Linux
《C++与 CUDA:开启人工智能算法加速之旅》
在AI快速发展的今天,计算效率成为关键挑战。CUDA作为英伟达推出的高性能并行计算平台,极大提升了AI算法的处理速度。本文详细介绍如何在C++环境中安装配置CUDA库,包括系统要求、安装步骤、验证方法及优化技巧,助力开发者高效利用GPU加速AI应用,开启算法加速的新篇章。
226 25
|
10月前
|
数据可视化 搜索推荐 API
速卖通获得aliexpress商品详情API接口的开发、应用与收益。
速卖通(AliExpress)作为阿里巴巴旗下的跨境电商平台,为全球消费者提供丰富商品。其开放平台提供的API接口支持开发者获取商品详情等信息,本文探讨了速卖通商品详情API的开发流程、应用场景及潜在收益,包括提高运营效率、降低成本、增加收入和提升竞争力等方面。
300 1
|
12月前
|
人工智能 语音技术 数据格式
三文带你轻松上手鸿蒙的AI语音01-实时语音识别
三文带你轻松上手鸿蒙的AI语音01-实时语音识别
313 0
三文带你轻松上手鸿蒙的AI语音01-实时语音识别
|
人工智能 自然语言处理 数据管理
阿里云百炼产品月刊【2024年7月】
阿里云百炼产品月刊【2024年7月】,涵盖本月产品和功能发布、市场活动和应用实践等内容,帮助您快速了解阿里云百炼产品的最新动态。
919 0
|
存储 人工智能 安全
机密计算容器前沿探索与 AI 场景应用
机密计算容器前沿探索与 AI 场景应用
|
Java Maven
查找maven中的groupId,artifactId,version等信息的方式
可以查看:http://search.maven.org/   输入要想找的东西 
2417 0