1
votes

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

1 Answers

3
votes

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://docs.microsoft.com/en-us/azure/documentdb/documentdb-nodejs-get-started#a-idqueryastep-8-query-documentdb-resources for more info.