我正在尝试将数据从 Azure 函数输出到 CosmosDb (MongoDb),我有以下绑定(bind)设置:
[DocumentDB("mydatabase", "mycollection",
ConnectionStringSetting = "CosmosDBConnection",
CreateIfNotExists= true,
PartitionKey = "SomeKey")]
IAsyncCollector<MyEntity> mongoBinding,
在我的代码中,我执行以下操作:
var entity = new MyEntity() {SomeKey="X1CLX1010000002", Data = "somedata"};
await mongoBinding.AddAsync(entity);
public class MyEntity {
public string SomeKey {get; set;}
public string Data {get; set;}
}
结果错误:
{"Errors":["The partition key component definition path 'SomeKey' could not be accepted, failed near position '0'. Partition key paths must contain only valid characters and not contain a trailing slash or wildcard character."]}
知道我做错了什么吗?
最佳答案
解决方案是在 key 开头添加斜杠,例如 PartitionKey = "/SomeKey"
。那么分区键就像一个路径,因此它需要以“/”开头。你没有使用斜杠,所以出现上面的错误。
关于azure-functions - AF 绑定(bind)到 CosmosDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51520603/