1

I'm using the node sdk for document db and I'm able to successfully list all the documents in my collection with the following code:

collectionUrl = "dbs/dbName/colls/Membership"
this.client.readDocuments(this.collectionUrl).toArray(callback)

But when I try to query the data with the following code it fails:

querySpec = {
  query: 'SELECT * FROM root r '
};
this.client.queryCollections(this.collectionUrl,this.querySpec).toArray(callback)

The error message is:

 body:"{"code":"BadRequest","message":"Request url is invalid.\r\nActivityId: 532e52d2-7e97-41d4-8b07-a5fb19de88da"}"
 code:400

Any idea why this is an what i need to do to execute a query?

1 Answer 1

3

I found that you are using queryCollections function to for querying documents. Please try to use: this.client.queryDocuments(this.collectionUrl,this.querySpec).toArray(callback) instead.

If you want to query collections in your db, please use databaseLink in stead of collectionUrl, which should be like dbs/dbName. You can refer to https://github.com/Azure/azure-documentdb-node/blob/master/source/lib/documentclient.js#L813 for the source code.

Please refer to https://learn.microsoft.com/en-us/azure/documentdb/documentdb-nodejs-get-started#a-idqueryastep-8-query-documentdb-resources for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank-you I misunderstood the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.