【发布时间】:2017-07-18 02:27:18
【问题描述】:
我正在尝试使用文档 ID 从 DocumentDB 读取单个文档。该集合有四个字段,author 是分区键。
{
"id": string,
"author": string,
"title": string,
"year": int
}
我有两个函数用于读取存储在 DocumentDB 中的记录。 queryCollectionByBookId 按文档 ID 读取单个文档,queryCollectionGetBooks 返回集合中的所有文档。
var dbutils = {
queryCollectionByBookId: function(client, documentUrl) {
return new Promise((resolve, reject) => {
client.readDocument(documentUrl, function(err, doc) {
if (err) {
reject(err);
} else {
resolve(doc);
}
});
});
},
queryCollectionGetBooks: function(client, collectionUrl) {
return new Promise((resolve, reject) => {
client.readDocuments(collectionUrl).toArray((err, results) => {
if (err)
reject(err);
else {
resolve(results);
}
});
});
}
};
queryCollectionGetBooks 函数工作正常,但queryCollectionByBookId 返回以下错误消息。
{"Errors":["The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection."]}
有其他人看到此错误消息并找到解决方法吗?
【问题讨论】:
标签: javascript node.js azure-cosmosdb