尝试从节点查询 documentDB 时请求 url 无效

Request url is invalid when trying to query documentDB from node

我正在使用文档数据库的节点 sdk,我能够使用以下代码成功列出我的集合中的所有文档:

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

但是当我尝试使用以下代码查询数据时,它失败了:

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

错误信息是:

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

知道为什么我需要执行查询吗?

我发现您正在使用 queryCollections 函数来查询文档。请尝试使用: this.client.queryDocuments(this.collectionUrl,this.querySpec).toArray(callback) 相反。

如果您想在您的数据库中查询 collections,请使用 databaseLink 而不是 collectionUrl,它应该类似于 dbs/dbName。源码可以参考https://github.com/Azure/azure-documentdb-node/blob/master/source/lib/documentclient.js#L813

更多信息请参考https://docs.microsoft.com/en-us/azure/documentdb/documentdb-nodejs-get-started#a-idqueryastep-8-query-documentdb-resources