I'm trying to read a single document from DocumentDB by using the document ID. The collection has four fields, author being the partition key.
{
"id": string,
"author": string,
"title": string,
"year": int
}
I have two functions for reading the records stored into DocumentDB. queryCollectionByBookId reads a single document by document id and queryCollectionGetBooks returns all the documents in the collection.
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 function works fine, but queryCollectionByBookId returns the error message below.
{"Errors":["The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection."]}
Has anyone else seen this error message and found out how to resolve it?