I'm using CosmosDB (node.js via documentdb api) - partitioned on 'id' only.
A simple query (SELECT * FROM c WHERE c.akunaCustomer = "xyz"
) works fine from Azure Query Explorer, but my node.js code gives the following error - running the identical query.
code: 400, BadRequest, 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.
Here's my code:
var documentClient = require("documentdb").DocumentClient;
var config = require("./config");
var client = new documentClient(config.endpoint, {"masterKey": config.primaryKey});
var databaseUrl = `dbs/${config.database.id}`;
var collectionUrl = `${databaseUrl}/colls/${config.collection.id}`;
client.queryDocuments(collectionUrl,
'SELECT * FROM c WHERE c.akunaCustomer = "xyz"'
).toArray((err, results) => {
if(err) {
console.log(err);
}
else {
for (var queryResult of results) {
let resultString = JSON.stringify(queryResult);
console.log(`Query: ${resultString}`);
}
}
});
Clearly I'm missing something. :-( Any help would be appreciated.
Service port ranges The port 10250 maps to a default Azure Cosmos DB API for MongoDB instance without geo-replication.
Quick note: Core (SQL) API is the native API in Cosmos DB and is also called SQL API. It supports a SQL-like query language that allows retrieving documents using SELECT and other basic SQL commands.
The error message is quite clear: because your query spans multiple partitions, you need to set enableCrossPartitionQuery
option to true
:
client.queryDocuments(
collectionUrl,
'SELECT * FROM c WHERE c.akunaCustomer = "xyz"',
{ enableCrossPartitionQuery: true }
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With