我可以在Cosmos上存储文档,没有问题。但是我不能使用"读取"方法检索它们
this.cosmos = new CosmosClient({
endpoint: ''
key: ''
});
this.partitionKey = '/id'
this.container = this.cosmos.database('test').container('test');
type Data = {
value: string;
} & ItemDefinition;
// read it
const { resource } = await this.container.item(key, this.partitionKey).read<Data>();
console.log('>>>', JSON.stringify(resource));
图纸x1月1x
我做错了什么?
UPDATE:statusCode为404,但数据库中存在该对象。
1条答案
按热度按时间ylamdve61#
分区键必须是值,而不是路径。
这就是真理之路。
如果您有一个ID为
A
的项,则由于您的分区键路径为/id
,因此分区键值是该项中该属性的值,也是A
。例如,如果您的分区密钥路径为
/someOtherProperty
,并且您有一个项目:然后,要读它,你会这样做: