创建 Azure Cosmos DB 帐户、数据库和集合
運行所示的命令,以創建 Azure Cosmos DB 帳戶、數據庫和集合:
export NAME="jacksun"
export RESOURCE_GROUP="92116f19-67b4-4078-8e64-b488b5c5cede"
export LOCATION="EastUS"
export DB_NAME="Products"
az cosmosdb create --name $NAME --kind GlobalDocumentDB --resource-group $RESOURCE_GROUP
az cosmosdb database create --name $NAME --db-name $DB_NAME --resource-group $RESOURCE_GROUP
az cosmosdb collection create --collection-name "Clothing" --partition-key-path "/productId" --throughput 1000 --name $NAME --db-name $DB_NAME --resource-group $RESOURCE_GROUP
?
SELECT * FROM Products p WHERE p.id ="1"
SELECT p.id, p.manufacturer, p.description FROM Products p WHERE p.id ="1"
SELECT * FROM Products.shipping
SELECT * FROM Products.shipping.weight
SELECT p.price, p.description, p.productId FROM Products p ORDER BY p.price ASC
SELECT p.productId FROM Products p JOIN p.shipping
JOIN 子句可實現文檔和文檔子根的內聯。 因此,在產品數據庫中,可將文檔與傳送數據相結合。
function createMyDocument() {
var context = getContext();
var collection = context.getCollection();
var doc = {
"id": "3",
"productId": "33218898",
"description": "Contoso microfleece zip-up jacket",
"price": "44.99"
};
var accepted = collection.createDocument(collection.getSelfLink(),
doc,
function (err, documentCreated) {
if (err) throw new Error('Error' + err.message);
context.getResponse().setBody(documentCreated)
});
if (!accepted) return;
}
-------------------------------------
function producttax(price) {
if (price == undefined)
throw 'no input';
var amount = parseFloat(price);
if (amount < 1000)
return amount * 0.1;
else if (amount < 10000)
return amount * 0.2;
else
return amount * 0.4;
}
---------------------------
SELECT c.id, c.productId, c.price, udf.producttax(c.price) AS producttax FROM c -----------------------?
[ { "id": "1", "productId": "33218896", "price": "14.99", "producttax": 1.499 }, { "id": "2", "productId": "33218897", "price": "49.99", "producttax": 4.9990000000000006 }, { "id": "3", "productId": "33218898", "price": "44.99", "producttax": 4.4990000000000006 } ]?
轉載于:https://www.cnblogs.com/sundy818/p/10445167.html
總結
以上是生活随笔為你收集整理的创建 Azure Cosmos DB 帐户、数据库和集合的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高性能 DotNetty Server
- 下一篇: 向日葵权限mac