《Windows Azure Platform 系列文章目录

  The SQL API supports the following aggregate functions. SUM and AVG operate on numeric values, and COUNT, MIN, and MAX work on numbers, strings, Booleans, and nulls.

  在本章节,我们将使用Azure Portal,创建1个Azure Cosmos DB。

  1.首先,我们登录Azure China Portal: https://portal.azure.cn

  2.选择Azure Cosmos DB

  

  

  3.创建新的资源组,命名为cosmos-rg

  创建新的account name:leicosmos

  API设置为Core(SQL)

  

  4.CosmosDB暂时不选择虚拟网络,图略。

  注意:创建完毕后,cosmos DB并不会开始收费,因为我们没有分配RU

  5.创建完毕后,我们选择该资源,点击Data Explorer

  点击New Database,我们输入新的database id

  

  如上图所示,RU可以分配在Database级别。这样Database下面的所有Collection都共享这个Database的RU

  我们这里暂时不勾选Provision throughput。

  注意:创建Database完毕后,cosmos DB并不会开始收费,因为我们没有分配RU

  6.在上一步操作完毕后,我们点击Products,点击右键,New Collection

  

  7.在右侧弹出的窗口中,输入下面的信息:

  

  我们定义了Partition Key分区键为/country,

  Throughput最小为400

  定义了Unique Keys为/productionId

  这个操作完毕后,cosmos DB已经开始收费,因为我们已经分配RU

  8.创建完毕后,界面展示如下:

  

  Database Level为Products

  Collection Level为clothing

  9.我们可以在界面上,插入新的Document。如下图:

  

  10.我们插入第一条数据

{
"id": "",
"productId": "",
"country":"China",
"category": "Women's Clothing",
"manufacturer": "Contoso Sport",
"description": "Quick dry crew neck t-shirt",
"price": "14.99",
"shipping": {
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
}
}

  点击Save保存。

  执行成功后,截图如下:

  

  10.然后我们重复步骤9中的New Document,插入第二条数据

  请注意:我们在步骤7中,创建新的Collection的时候,定义了Unique Key为productId

  表示在同一个Partition Key中,productId不能重复

  

  观察下面的数据中,"country":"China",是与步骤9中的数据,保存在同一个Partition Key里

  "productId": "33218896",是与上面步骤9中的数据相同

{
"id": "",
"productId": "",
"country":"China",
"category": "Women's Outerwear",
"manufacturer": "Contoso",
"description": "Black wool pea-coat",
"price": "49.99",
"shipping": {
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
}
}

  执行Save操作,会出现约束错误

  

  

  11.我们在修改productId为33218897。插入下面的值

{
"id": "",
"productId": "",
"country":"China",
"category": "Women's Outerwear",
"manufacturer": "Contoso",
"description": "Black wool pea-coat",
"price": "49.99",
"shipping": {
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
}
}

  执行成功

  12.我们还可以插入其他值:

{
"id": "3",
"productId": "",
"country":"US",
"category": "Women's Outerwear",
"manufacturer": "Contoso",
"description": "Black wool pea-coat",
"price": "29.99",
"shipping": {
"weight": ,
"dimensions": {
"width": ,
"height": 4,
"depth":
}
}
}

  这样一共就插入了三个数据

  Query

  13.我们执行下面的语句:

SELECT * FROM Products c where c.id=""

  查询结果

[
{
"id": "",
"productId": "",
"country": "China",
"category": "Women's Clothing",
"manufacturer": "Contoso Sport",
"description": "Quick dry crew neck t-shirt",
"price": "14.99",
"shipping": {
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
},
"_rid": "BekdAKyBIekBAAAAAAAAAA==",
"_self": "dbs/BekdAA==/colls/BekdAKyBIek=/docs/BekdAKyBIekBAAAAAAAAAA==/",
"_etag": "\"00001a00-0000-4200-0000-5cb6e4dd0000\"",
"_attachments": "attachments/",
"_ts":
}
]

  14.我们执行下面的语句

SELECT
p.id,
p.manufacturer,
p.description
FROM Products p
WHERE p.id =""

  执行结果:

[
{
"id": "",
"manufacturer": "Contoso Sport",
"description": "Quick dry crew neck t-shirt"
}
]

  FROM

  15.我们执行下面的语句:

SELECT * FROM Products.shipping

  执行结果:

[
{
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
},
{
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
},
{
"weight": ,
"dimensions": {
"width": ,
"height": ,
"depth":
}
}
]

  16.我们执行下面的语句

SELECT * FROM Products.shipping.weight

  执行结果

[
,
, ]

  WHERE

  17.我们执行下面的语句

SELECT p.description
FROM Products p
WHERE p.id = ""

  执行结果

[
{
"description": "Quick dry crew neck t-shirt"
}
]

  Order By clause

  18.我们执行下面的语句

SELECT p.price, p.description, p.productId
FROM Products p
ORDER BY p.price ASC

  执行结果:

[
{
"price": "14.99",
"description": "Quick dry crew neck t-shirt",
"productId": ""
},
{
"price": "29.99",
"description": "Black wool pea-coat",
"productId": ""
},
{
"price": "49.99",
"description": "Black wool pea-coat",
"productId": ""
}
]

  JOIN

  19.我们执行下面的语句:

SELECT p.productId
FROM Products p
JOIN p.shipping

  执行结果:

[
{
"productId": ""
},
{
"productId": ""
},
{
"productId": ""
}
]

  

  查询MAX

  20.我们执行下面的语句

SELECT value MAX(c.productId) FROM clothing c

  执行结果

[
""
]

Azure CosmosDB (12) 创建Cosmos DB并执行查询语句的更多相关文章

  1. Azure Cosmos DB (三) EF Core 操作CURD

    一,引言 接着上一篇使用 EF Core 操作 Azure CosmosDB 生成种子数据,今天我们完成通过 EF Core 实现CRUD一系列功能.EF Core 3.0 提供了CosmosDB 数 ...

  2. Azure Cosmos DB (二) SQL API 操作

    一,引言 还记得国庆期间,我们学习了一下关于Azure Cosmos DB 的一些基础知识以及Azure Cosmos DB 的几种支持数据库类型.今天就开始分享一些实战操作,如何通过Azure Po ...

  3. 使用 Cosmos DB 创建和查询 NoSQL 表

    本教程演示如何使用 Azure 门户创建 Azure Cosmos DB 帐户,然后使用 DocumentDB .NET API 创建具有分区键的文档数据库和集合.通过在创建集合时定义分区键,应用程序 ...

  4. Azure Cosmos DB介绍及演示

    Azure Cosmos DB 是 Microsoft 提供的全球分布式多模型数据库服务.Cosmos DB是一种NoSql数据库,但是它兼容多种API.它支持SQL, MongoDB.Cassand ...

  5. Azure CosmosDB (10) Azure Cosmos DB体系结构

    <Windows Azure Platform 系列文章目录> Azure Cosmos DB的体系结构分为以下几个部分: 1.Database Accounts Database Acc ...

  6. Azure Cosmos DB (五) .Net Core 控制台应用

    一,引言 之前在讲Azure CosmosDB Core(SQL)核心的时候,使用了EF Core 的方式,引用了 "Microsoft.EntityFrameworkCore.Cosmos ...

  7. Azure Cosmos DB 使用费用参考

    之前在学习Cosmos DB 中SQL API(DocumentDB) 的时候,也就是之前做的一些笔记,看到有使用费用的一些介绍,就有兴趣的去了解了下,做了一下简单的总结. 想了解更多或是购买使用的还 ...

  8. Azure Cosmos DB (四) 使用EF的SQL API 异地冗余

    一,引言 上一篇文章中,我们介绍到使用了EF Core 与Cosmos DB SQL API 进行结合开发.同时,大家在开发过程中一定要记得EF Core 不支持Cosmos DB 的迁移.今天我们启 ...

  9. NCF 的Azure Cosmos DB 演示案例

    简介 NCF想必看过我之前发的NCF的文章的同学们都已经很熟悉了 今天我们要来聊一聊的是NCF遇到Azure Cosmos DB后会碰撞出什么样的火花,让我们一起往下看 我们先来说说什么是Azure ...

随机推荐

  1. 泊爷带你学go -- redis连接池的操作

    package main import ( "common" "fmt" "proto" "strconv" " ...

  2. docker info 警告"WARNING: No swap limit support"

    vim/etc/default/grub 找到 GRUB_CMDLINE_LINUX="" 在双引号里面输入cgroup_enable=memory swapaccount=1 然 ...

  3. centOS6.0虚拟机ip配置

    1.首先使用虚拟机安装好centOS6.0系统 2.虚拟机网络配置:(选择桥接模式) 3. 第一步:首先关闭防火墙 1.将防火服务从启动列表移除 #chkconfig --del iptables # ...

  4. Python基础学习总结(持续更新)

    https://www.cnblogs.com/jin-xin/articles/7459977.html 嗯,学完一天,白天上班,眼睛要瞎了= = DAY1 1,计算机基础. CPU:相当于人的大脑 ...

  5. redis客户端(三)

    redis客户端 一.>redis自带的客户端 启动 启动客户端命令:[root@ming bin]# ./redis-cli -h xxx.xxx.xx.xxx-p 6379 注意: -h:指 ...

  6. 学习java一个月的进展

    作为一个阶段性总结,有很多的东西需要说明,有细节的,有架构的,且听我细细说来. java和php最大的区别不止是类型的强制定义,而是在设计思路上有着非常重大的偏差(虽然SY3框架已经开始借鉴JAVA的 ...

  7. wps 邮件 通讯小灵通 长沙杭州

    记得在天涯上看过一个热贴,关于贵族与世家的,文中提到号称当今贵族的六大世家,什么“汝南周氏”.“吴兴沈氏”之类,更有甚者,为了比拼,追本溯源,把孔子他老人家也抬了出来,号称孔夫子的多少多少代传人,当时 ...

  8. 处理文件中的" M-BM- "特殊符号

    有时为了方便,会在Excel中进行代码拼装,比如说是建表SQL语句,但是在复制的代码过程中可能会带入不可见字符,造成代码无法运行. 本次代码中就需要了不可见的" M-BM- " 问 ...

  9. Altium Designer 10 快捷键笔记

    一.放置.走线类: 1.交互式走线(Track):P T 2.铺铜(Fill):P F 3.大面积铺铜(Polygon):P G 4.自动扇出:元件封装上右键,C F 二.编辑类 1.调整铺铜(Pol ...

  10. Ubuntu文件系统

    (). 关于Linux中的文件: (). 在Linux系统中, 一切都是文件 : 所有数据都是文件,包括设备. (). 最小的数据存储单元也是文件. (). 文件系统: 文件系统就是文件的组织和管理方 ...