Skip to content

[Bug] Cosmos DB Input Binding (Node.js) with enableCrossPartitionQuery=true Returns Empty Array Despite Matching Documents #766

@Ruelmas

Description

@Ruelmas

Body:

Hi team,

I'm in Ops, not a dev, but caught a potential issue in the Cosmos DB input binding for Azure Functions (Node.js) that might be worth a look.

💥 Problem
The binding returns an empty array ([]) when using enableCrossPartitionQuery: true, even though the data exists and matches the query. However, the exact same query works when run via:

The Azure Portal Data Explorer

The @azure/cosmos SDK directly from the same function

This suggests a silent failure at the binding level, not in the data or query itself.

⚙️ Repro
Azure Function App

Language: Node.js (v18)

Plan: Consumption

Function: GetPatient (HTTP Trigger)

Binding (function.json)

json
Copy
Edit
{
"name": "patientDoc",
"type": "cosmosDB",
"direction": "in",
"databaseName": "HealthcareDB",
"containerName": "Patients",
"sqlQuery": "SELECT * FROM c WHERE c.patient_id = @patientID",
"partitionKey": null,
"enableCrossPartitionQuery": true,
"parameters": [
{
"name": "@patientID",
"value": "{patientId}"
}
]
}
Cosmos DB Details

DB: HealthcareDB

Container: Patients

Partition Key: /source

Verified Data: patient_id "P00100" exists (17 records across multiple partitions)

❌ Behavior
patientDoc from the binding is always []

SDK-based query with same settings returns all expected documents

✅ Workaround (SDK)
js
Copy
Edit
const { CosmosClient } = require('@azure/cosmos');
const client = new CosmosClient(process.env.COSMOS_CONN);
const container = client.database('HealthcareDB').container('Patients');

const querySpec = {
query: 'SELECT * FROM c WHERE c.patient_id = @patientID',
parameters: [{ name: '@patientID', value: patientId }],
};

const { resources } = await container.items
.query(querySpec, { enableCrossPartitionQuery: true })
.fetchAll();
Returns expected results immediately.

📈 Impact
This affected a healthcare proof-of-concept (100+ patients, 20 records each), where relying on the binding would’ve silently dropped all patient data. Required moving to SDK-based logic for reliability.

🧠 My Take
Looks like the binding isn’t honoring enableCrossPartitionQuery: true in some edge cases. Happy to help further if logs or an isolated Function App are needed.

Thanks!
– Ruel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions