初始化Azure Cosmos DB连接并上传数据

时间:2019-04-22 20:31:21

标签: f# azure-cosmosdb

我是F#的新手,并且想找到有关如何使用F#创建函数App并将数据向上插入到cosmos DB中的任何参考

1 个答案:

答案 0 :(得分:0)

您可以按照此example的想法

let private createCollection (dbUri:Uri) (throughput:int) (client:DocumentClient) =
    let collection = DocumentCollection( Id = collectionName)

    // always use partition key
    collection.PartitionKey.Paths.Add(sprintf "/%s" partitionKey)

    // unique keys
    let streamPath = new System.Collections.ObjectModel.Collection<string>()
    streamPath.Add("/streamId")
    streamPath.Add("/position")
    let keys = new System.Collections.ObjectModel.Collection<UniqueKey>()
    keys.Add(UniqueKey( Paths = streamPath))
    collection.UniqueKeyPolicy <- UniqueKeyPolicy(UniqueKeys = keys)

    // throughput
    let throughput = throughput |> Throughput.correct
    let ro = new RequestOptions()
    ro.OfferThroughput <- Nullable<int>(throughput)

    task {
        let! _ = client.CreateDocumentCollectionIfNotExistsAsync(dbUri, collection, ro)
        return ()
    }