Skip to content

Latest commit

 

History

History
81 lines (69 loc) · 2.32 KB

cosmos-db.md

File metadata and controls

81 lines (69 loc) · 2.32 KB

CosmosDB

CosmosDB can be added to the list of required connections.

Config (Connection)

To enable Cosmos DB data sources add 'cosmos-db' to the connections config. The host name and password key are required values.

connections: {
  'cosmos-db': { 
    'host': "",
    'key': ""
  }
}

NB. The host name excludes the '.documents.azure.com' suffix.

Returned Structure

{
  'Documents': any[],
  '_count': number,
  '_rid': 'request id'
}

Data Sources

Property Type Value Description
id string ID of the element
type string "CosmosDB/Query" Data source plugin name
dependencies object A collection of key values referenced by queries
params object Contains databaseId, collectionId, query and parameters
calculated function Result contains array of Documents, _rid and _count properties.

Params

Property Type Description
databaseId string Database Id (default is 'admin')
collectionId string Collection Id
query string SQL query string
parameters object[] Parameterized SQL request

More info about SQL query string and parameters are available in the CosmosDB documentation. You can try out Cosmos DB queries using the Query Explorer in the Azure portal, or learn using the SQL demo.

Sample data source

{
  id: "botConversations",
  type: "CosmosDB/Query",
  dependencies: { timespan: "timespan", queryTimespan: "timespan:queryTimespan" },
  params: {
  	databaseId: "admin",
  	collectionId: "conversations",
  	query: () => `SELECT * FROM conversations WHERE (conversations.state = 0)`,
  	parameters: []
  },
  calculated: (result) => {
    return result;
  }
}

Sample element

{
  id: "conversations",
  type: "Scorecard",
  title: "Conversations",
  subtitle: "Total conversations",
  size: { w: 4, h: 3 },
  dependencies: {
  	card_conversations_value: "botConversations:_count",
  	card_conversations_heading: "::Conversations",
  	card_conversations_icon: "::chat"
  }
}