- DocumentDB 教程
- DocumentDB - 首頁
- DocumentDB - 簡介
- DocumentDB - 優勢
- DocumentDB - 環境設定
- DocumentDB - 建立賬戶
- DocumentDB - 連線賬戶
- DocumentDB - 建立資料庫
- DocumentDB - 列出資料庫
- DocumentDB - 刪除資料庫
- DocumentDB - 建立集合
- DocumentDB - 刪除集合
- DocumentDB - 插入文件
- DocumentDB - 查詢文件
- DocumentDB - 更新文件
- DocumentDB - 刪除文件
- DocumentDB - 資料建模
- DocumentDB - 資料型別
- DocumentDB - 限制記錄
- DocumentDB - 排序記錄
- DocumentDB - 索引記錄
- DocumentDB - 地理空間資料
- DocumentDB - 分割槽
- DocumentDB - 資料遷移
- DocumentDB - 訪問控制
- DocumentDB - 資料視覺化
- DocumentDB 有用資源
- DocumentDB - 快速指南
- DocumentDB - 有用資源
- DocumentDB - 討論
DocumentDB - 資料型別
JSON(JavaScript 物件表示法)是一種輕量級的基於文字的開放標準,旨在用於人類可讀的資料交換,並且易於機器解析和生成。JSON 是 DocumentDB 的核心。我們透過網路傳輸 JSON,將 JSON 儲存為 JSON,並索引 JSON 樹,從而允許對完整的 JSON 文件進行查詢。
JSON 格式支援以下資料型別:
| 序號 | 型別和描述 |
|---|---|
| 1 | 數字 JavaScript 中的雙精度浮點數格式 |
| 2 | 字串 帶反斜槓轉義的雙引號 Unicode 字串 |
| 3 | 布林值 真或假 |
| 4 | 陣列 一個有序的值序列 |
| 5 | 值 它可以是字串、數字、true 或 false、null 等。 |
| 6 | 物件 一個無序的鍵值對集合 |
| 7 | 空格 它可以在任何一對標記之間使用 |
| 8 | 空值 空 |
讓我們來看一個簡單的 DateTime 型別示例。將出生日期新增到客戶類。
public class Customer {
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
// Must be nullable, unless generating unique values for new customers on client
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "address")]
public Address Address { get; set; }
[JsonProperty(PropertyName = "birthDate")]
public DateTime BirthDate { get; set; }
}
我們可以使用 DateTime 進行儲存、檢索和查詢,如下面的程式碼所示。
private async static Task CreateDocuments(DocumentClient client) {
Console.WriteLine();
Console.WriteLine("**** Create Documents ****");
Console.WriteLine();
var document3Definition = new Customer {
Id = "1001",
Name = "Luke Andrew",
Address = new Address {
AddressType = "Main Office",
AddressLine1 = "123 Main Street",
Location = new Location {
City = "Brooklyn",
StateProvinceName = "New York"
},
PostalCode = "11229",
CountryRegionName = "United States"
},
BirthDate = DateTime.Parse(DateTime.Today.ToString()),
};
Document document3 = await CreateDocument(client, document3Definition);
Console.WriteLine("Created document {0} from typed object", document3.Id);
Console.WriteLine();
}
編譯並執行上述程式碼後,建立文件後,您將看到現在已添加出生日期。
**** Create Documents ****
Created new document: 1001
{
"id": "1001",
"name": "Luke Andrew",
"address": {
"addressType": "Main Office",
"addressLine1": "123 Main Street",
"location": {
"city": "Brooklyn",
"stateProvinceName": "New York"
},
"postalCode": "11229",
"countryRegionName": "United States"
},
"birthDate": "2015-12-14T00:00:00",
"_rid": "Ic8LAMEUVgAKAAAAAAAAAA==",
"_ts": 1450113676,
"_self": "dbs/Ic8LAA==/colls/Ic8LAMEUVgA=/docs/Ic8LAMEUVgAKAAAAAAAAAA==/",
"_etag": "\"00002d00-0000-0000-0000-566efa8c0000\"",
"_attachments": "attachments/"
}
Created document 1001 from typed object
廣告