I am try to query a DocumentDB that has a partition key using Node.js but it fails. According to here - https://stackoverflow.com/a/43002819/7799859 - I need to pass the partition key is some object that is called options.
Can anyone tell me where I can find examples for this options.partitionKey or options.enableCrossPartitionQuery?
What is this options object? How do I create it in NodeJS?
This is my code:
find: function (querySpec, callback)
{
var self = this;
console.log(self.collection);
console.log(self.collection._self);
console.log(this.collectionUrl);
var options = {
partitionKey: "myCustomKey"
};
self.client.queryDocuments(this.collectionUrl, querySpec,options).toArray(function (err, results) {
if (err) {
callback(err);
} else {
callback(null, results);
}
});
}
I added the options var, but when I send it no results are returned.
When I don't send it, this is the error:
{"code":"BadRequest","message":"Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.\r\nActivityId: e4103506-d352-46d5-97d0-740d89065955"}
I am using Node version 4.2.6 and the latest version of documentdb. @GaryLiu-MSFT this is from package.json file:- "documentdb": "^1.10.0",
This is my querySpec:
var querySpec = { query: 'SELECT * FROM root', };