Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross partition query is required but disabled #84

Open
vipinsorot opened this issue Aug 17, 2023 · 3 comments
Open

Cross partition query is required but disabled #84

vipinsorot opened this issue Aug 17, 2023 · 3 comments

Comments

@vipinsorot
Copy link

I have migrated a collection, post migration when i am switching to new db endpoints, i am getting an error
Error: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., documentdb-dotnet-sdk/2.11.6

sharing old collection setting
image
new collection setting
image

@joelhulen
Copy link

Thank you for reaching out about this issue. By default, when querying a Cosmos DB container using the SDK, cross-partition queries are disabled. This is because you should try and limit executing cross-partition queries as much as possible by ensuring the partition key is included in your queries. While cross-partition queries are sometimes unavoidable and OK, excessive querying across partitions comes with a high cost (in RU/s and performance).

What you need to do in your application code that is making the call to your new container is to update the FeedOptions to enable cross-partition queries with the EnableCrossPartitionQuery property. Here's an example:

var queryable = client.CreateDocumentQuery<Book>(
    collectionLink, new FeedOptions { EnableCrossPartitionQuery = true }).Where(b => b.Price > 1000);

@vipinsorot
Copy link
Author

Thanks @joelhulen for quick response

@aparna198809
Copy link

One of our customers mentioned the query was working fine for them without adding crosspartitionquery for their old account .But on the new account with exact same configuration it is giving this error .Was there a change implemented which worked for old accounts and stopped working off late ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants