How the collection is different from the schema

I am very new to cosmosdb(documentdb), while going through the documentation I keep on reading one thing repeatedly that documentdb is schema free but I feel like collection in analogous to schema and both are logical view.

Wikipedia
defined schema as ‘The term “schema” refers to the organization of data as a blueprint of how the database is constructed’. I believe collection is also same it’s the organization of document, stored prcedure, triggers and UDF.

So my question is, how schema is different from collection?

The schema of relational databases is slightly different from the schema of document databases. In simple terms, a relational database is stricter than that of a document schema. In other words, records in an RDBMS table must strictly adhere to the schema, where as we have some amount of flexibility while storing a document into a Document collection.

Conventionally a collection is a set of documents which follows the same schema. But document DBs don’t stop one from storing documents with different schema in a single collection. It is the flexibility it gives to the users.

Let us take an example. Let us assume we are storing some customer information. In relational DB, we might have some structure like

Customer ID INT
Name        VARCHAR(50)
Phone       VARCHAR(15)
Email       VARCHAR(255)

Depending on customer having an email or phone number, they will be recorded as proper values or null values.

ID, Name, Phone, Email
1, John, 83453452, -
2, Victor, -, -
3, Smith, 34535345, [email protected]

However in document databases, some columns need to appear in the collection, if they don’t have any values.

[
{
  id: "123",
  name: "John",
  phone:"2572525",
},
{
  id: "456",
  name: "Stephen",
},
{
  id: "789",
  name: "King",
  phone:"2572525",
  email:"[email protected]"
}
]

However it is always advisable to stick to a schema in document db’s even if they provide flexibility to store schema-less documents to a collection for maintainability purposes.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » How the collection is different from the schema

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录