CouchDB中的Schemas詳解

jieforest發表於2012-09-10
1 technical a representation of a plan or theory in the form. of an outline or model: a schema of scientific reasoning.

2 Logic a syllogistic figure.

3 (in Kantian philosophy) a conception of what is common to all members of a class; a general or essential type or form.

CouchDB is a schema-less document store, but there are times when a schema is a good thing to have around, one way or another. So can you have your cake and eat it too?

Below I'll take a high level look at adding a kind of schema to an application and the benefits and draw backs associated with this way of working. What I describe below isn't for everyone. It goes against some of the core principles of CouchDB and makes your data much less human readable, but there are cases where that trade off is worth making.

[b]Schemas: WTF?![/b]

It might seem a bit weird to add a schema to a schema-less database but sometimes it is a very useful thing indeed. When you're dealing with large datasets verbose object key names can be a problem (e.g. cost you money) so you end up stuck between a rock and a hard place; either make your data terse and hard to use or be explicit and spend more on storage and network.

1.{
2."shape": "triangle",
3."colour_label": "red",
4."opposite_length_in_mm": 767.12254256805875,
5."angle_in_radians": 1.5514293603308698,
6."adjacent_length_in_mm": 73.59881843627835
7.}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-742994/,如需轉載,請註明出處,否則將追究法律責任。

相關文章