Azure Cosmos DB 2 Cheat Sheet v4 PDF
Azure Cosmos DB 2 Cheat Sheet v4 PDF
},
"givenName":"Goofy"
Built-in functions "ok": 1, { > db.families.remove(
"familyName":"Miller",
{ "CommandName": "OP_QUERY", {id: "SmithFamily"} )
"givenName":"Shadow" SELECT * "givenName":"Ben"
ABS, CEILING, EXP, FLOOR, LOG,
} Parameterized FROM Families f "RequestCharge": 2.48, }
LOG10, POWER, ROUND, SIGN, SQRT, WriteResult( {"nRemoved" : 1} )
] SQL WHERE f.lastName = @lastName AND ],
}, Mathematical SQUARE, TRUNC, ACOS, ASIN, ATAN, f.address.state = @addressState
"RequestDurationInMilliSeconds":
"children":[
{ ATN2, COS, COT, DEGREES, PI, 4.0048} {
"familyName":"Miller", RADIANS, SIN, and TAN
"givenName":"Lisa", SELECT Families.id, Families.ad-
"familyName":"Merriam",
"givenName":"Jesse",
Aggregate queries
"gender":"female", IS_ARRAY, IS_BOOL, IS_NULL,
dress.city
"grade":8 Type checking IS_NUMBER, IS_OBJECT, IS_STRING, String Built-in FROM Families Example: cars collection "gender":"female", Join family and cars collections to families with the
} IS_DEFINED, and IS_PRIMITIVE functions WHERE STARTSWITH(Families.id,
"grade":1,
], "pets":[ cars they own.
CONCAT, CONTAINS, ENDSWITH, INDEX_OF, "Wakefield") {
"address":{ {
LEFT, LENGTH, LOWER, LTRIM, REPLACE, "make":"Honda", > db.families.aggregate([
"state":"NY", String "owner":"WakefieldFamily", "givenName":"Goofy"
"county":"Manhattan", REPLICATE, REVERSE, RIGHT, RTRIM,
SELECT Families.id }, }, {
"city":"NY" STARTSWITH, SUBSTRING, and UPPER
}, Array Built-in FROM Families { { $lookup:
functions WHERE ARRAY_CONTAINS(Families.par- "givenName":"Shadow"
"creationDate":"2015-07-20T12:00Z", Array ARRAY_CONCAT, ARRAY_CONTAINS,
ents, { givenName: "Robin",
"make":"Toyata",
} {
"isRegistered":false ARRAY_LENGTH, and ARRAY_SLICE "owner":"AndersenFamily",
} familyName: "Wakefield" }) ] from: "cars",
},
ST_WITHIN, ST_DISTANCE, ST_INTERSECTS, },
Geospatial ST_ISVALID, and ST_ISVALIDDETAILED {
localField: "id",
© 2018 Microsoft Corporation. All rights reserved. Need help or have questions? Email us at [email protected] to talk to a Cosmos database engineer! www.cosmosdb.com | Tweet: @AzureCosmosDB, #cosmosdb
Azure Cosmos DB Query Cheat Sheet
Table API Gremlin / Graph API
Initialize a CloudTableClient Anatomy of Tinkerpop Graph Select a vertex by property Count number of vertices
Preflight table request Query entities Start with the g.v() selector, and filter using the Use the .count() step at the end of a traversal.
TableconnectionPolicy connectionPolicy =
.has ("key", "value") with any exisiting property
new TableConnectionPolicy() MHTTP Verb OPTIONS Method GET Vertex
{ as the key. Example:
UsedirectMode = true, http://myaccount.table.cosmosdb.azure.com/<table-resource> https://myaccount.table.cosmosdb.azure.com/mytable(Partitio- id: 3
<- Input
UseTcpProtocol = true, Key='<partition-key>',RowKey='<row-key>')?$select=<comma label: “ingredient”
EnableEndpointdiscovery = true Request Headers Example: :> g.V().out().hasLabel(“ingredient")
-separated-property-names> name: “cheese”
}; - Origin .count()
CloudStorageAccount storageAccount = https://myaccount.table.core.windows.net/mytable()?$fil- :> g.V().has("name", "sandwich")
- Access-Control-Request-Method
CloudStorageAccount.Parse(connectionString); ter=<query-expression>&$select=<comma-separated-propert
CloudTableClient = storageAccount.CreateCloudTable - Access-Control-Request-Headers Output ->
Client(connectionPolicy, Microsoft.Azure.Cosmos- y-names>
DB.ConsistencyLevel.BoundedStaleness); Edge Add an edge between two vertices
:> [2]
Request Headers Edge id: 5
Get table service stats
- Authorization - Date or x-ms-date id: 4 label: “has” After selecting a vertex, use the .addE("label") step,
Create a table Method GET
- x-ms-version - Accept label: “has” Vertex followed by any number of properties, then use the Return the path of a traversal
https://myaccount.table.cosmosdb.azure.com/?restype=ser- .to(g.V() …) to select another vertex to point it to.
CloudTable table = tableClient.GetTableRefer-
- x-ms-client-request-id id: 1 Use the .path() step at the end of a traversal,
vice&comp=stats
ence(" "); label: “food” use the .by() step to return values for a
table.CreateIfNotExists(); Request Headers name: “sandwich” Example:
Insert entity specific field.
- Authorization - Date or x-ms-date Vertex isDelicious: true :> g.V().has("name", "sandwich")
Method POST
Create table entity - x-ms-version - x-ms-client-request-id id: 2 .addE("has")
Example:
https://myaccount.table.cosmosdb.azure.com/mytable label: “ingredient” .property("amount", 2)
CustomerEntity item = new CustomerEntity() Request Headers name: “bread” .to(g.V().has("name", "bread")) <- Input
{ Query table
- Authorization - Date or x-ms-date :> g.V().out()
PartitionKey = Guid.NewGuid().ToString(), Method GET
RowKey = Guid.NewGuid().ToString(), - x-ms-version - Content-Type :> g.V().has("name", "sandwich") .path()
https://myaccount.table.cosmosdb.azure.com/Tables
Email = $" ",
PhoneNumber = "",
- Content-Length - Accept Graph object types .addE("has") .by("name")
© 2018 Microsoft Corporation. All rights reserved. Need help or have questions? Email us at [email protected] to talk to a Cosmos database engineer! www.cosmosdb.com | Tweet: @AzureCosmosDB, #cosmosdb