我正在尝试用我的await client.CreateDatabaseIfNotExistsAsync(new Database() { Id = "data"});
DocumentCollection dCollection = await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("data"), new DocumentCollection { Id = "coll"}, new RequestOptions { OfferThroughput = 400, , PartitionKey = new PartitionKey("/id") });
// dashboardCollection.PartitionKey.Paths.Add("/id");
代码创建一个天蓝色的宇宙数据库和集合。
portal.azure.com
当我转到Scale and Settings
并检查我的文档数据库时,便创建了集合。当我去Scale and Settings
进行收集时,没有看到分区键。
我手动创建了另一个集合,它在delete
部分中显示了分区键。
1
函数由于此分区键错误而引发错误
已将ID为partitionKey
的记录成功插入到文档DB中。以下删除失败,说明ResourceResponse<Document> response = await client.DeleteDocumentAsync(UriFactory.CreateDocumentUri("data", "coll", "1"), new RequestOptions { PartitionKey = new PartitionKey("1") });
无效。
class Node {
constructor(val) {
this.val = val
this.next = null
}
}
class LinkedList {
constructor(head) {
this.head = head
}
add(node) {
let start = this.head
if (start == null) this.head = node
else {
while (start.next) start = start.next
start.next = node
}
return this
}
/** Remove node from front of list and return its value */
shift() {
const item = this.head // x = Z.head (A)
this.head = this.head.next // Z.head = A.head.next (B)
console.log('(1)', this.head.val) // DEBUG: B <-- NEW
return item.val // x.val (A -- Original head ref value)
}
}
let listZ = new LinkedList()
.add(new Node('A'))
.add(new Node('B'))
.add(new Node('C'))
console.log('(2)', listZ.shift()) // A -- No longer a node in the list
答案 0 :(得分:1)
我来自CosmosDB工程团队。
创建DocumentCollection时,请确保在DocumentCollection对象中提供了分区键,如下所示:
PartitionKeyDefinition pkDefn = new PartitionKeyDefinition() { Paths = new Collection<string>() { "/id" } };
DocumentCollection dCollection = await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("data"), new DocumentCollection { Id = "coll", PartitionKey = pkDefn }, new RequestOptions { OfferThroughput = 400, PartitionKey = new PartitionKey("/id") });
在收集CRUD请求期间,不接受RequestOptions上的PartitionKey,因为我们希望PartitionKey成为收集对象的一部分。在文档CRUD请求期间,将使用RequestOptions上的PartitionKey。