Page 61 - MSDN Magazine, July 2017
P. 61
Figure 11 Output of the GitHub Code, Built Using ASP.NET Core, Angular and DocumentDB
name sounds: a collection of doc- uments. Because documents are flat, it’s better to think of them as flat objects and not like rows in a table. Coming from the SQL world, there’s a tendency to think of a col- lection as a table and documents like rows. However, that analogy has more problems than you might realize, especially when it comes to designing the architecture and later implementing it.
DocumentDB automatically handles all aspects of indexing. DocumentDB also supports speci- fying a custom indexing policy for collections during creation. Index- ing policies in DocumentDB are more flexible and powerful than secondary indexes offered in other database platforms because they let you design and customize the shape of the index without sac-
written to all replicas to make sure that subsequent requests can see the latest version.
Session:Thisisthemostpopularofall,andasthenamesuggests, is scoped to a client session. Imagine someone added a comment on a product on an eCommerce Web site. The user who commented should be able to see it; however, it will take some time before other users on the Web site can see it, too.
Eventual: As the name suggests, the replicas will eventually converge in absence of any additional writes. Eventual consis- tency provides the weakest read consistency, but offers the lowest latency for both reads and writes.
Architecture
DocumentDB Account has multiple databases. The database can be reached via the Uri [AccountUri]/ dbs/{id}, where AccountUri is of the pattern https://[account].documents.azure.net and whose database has the following collections (collections can be reached with the Uri [AccountUri]/dbs/{id}/colls/{id}):
• Documents—can be reached with the Uri [AccountUri]/ dbs/{id}/colls/{id}/docs/{id}
• Attachments—can be reached with the Uri [AccountUri]/ dbs/{id}/colls/{id}/docs/{id}/attachments/{id}
• Stored Procedures—can be reached with the Uri [Account- Uri]/ dbs/{id}/colls/{id}/sprocs/{id}
• Triggers—can be reached with the Uri [AccountUri]/ dbs/ {id}/colls/{id}/triggers/{id}
• User Defined Functions—can be reached with the Uri [AccountUri]/ dbs/{id}/colls/{id}/functions/{id}
• Users—can be reached with the Uri [AccountUri]/ dbs/{id}/ users/{id}. Users have permissions that can be reached with the Uri [AccountUri]/ dbs/{id}/users/{id}/permissions/{id}
The unit of record is a Document, and a collection is just as the
rificing schema flexibility.
DocumentDB models JSON documents and the indexes as
trees,andletsyoutunetopoliciesforpathswithinthetree.Youcan find more details in an introduction to DocumentDB indexing at bit.ly/2qg2Nqa. Within documents, you can choose which paths must be included or excluded from indexing. This results in improved write performance and lower index storage for scenarios when the query patterns are known beforehand.
In Figure 10, you see logical representation of the index for JSON documents.
Additional Info
Testing your query in DocumentDB is sometimes the hardest part of implementing it. Azure provides some ability to run que- ries through its portal, but I particularly like using DocumentDB Studio (studiodocumentdb.codeplex.com). Also, if you’re interested in checking out DocumentDB in more depth, checkout my Channel 9 Video on DocumentDB (bit.ly/2pJ6A2c).
Overall, Angular, Web API and Azure DocumentDB are each a great technology to have in your development arsenal, but com- bining them together, applications from as simple as hosting blog entries to as complex as an eCommerce Web site can be created. Figure 11 shows what can quickly be constructed when these three flexible and easy-to-implement technologies are used together.n
Chander dhall is a Microsoft MVP, Azure Advisor, ASP.NET Insider and Web API Advisor, as well as CEO of Cazton Inc. (cazton.com). He’s been active in speak- ing at top technical conferences around the world. Dhall also conducts workshops internationally to train top developers on ASP.NET Core, Angular, TypeScript, databases (both NoSQL and SQL) and many other technologies.
Thanks to the following Microsoft technical experts who reviewed this article: Govind Kanshi, Daniel Roth and Steve Sanderson
msdnmagazine.com
July 2017 55