Can't get simple CosmosDB query to work via Node.js - but works fine via Azure's Query Explorer

Viewed 2545

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.

1 Answers
Related