[英]How to fetch all documents from one of the collection of Azure's Cosmos DB using JAVA?
I gone through the documentation , there are two ways to fetch the documents我浏览了文档,有两种获取文档的方法
{ "code": "Forbidden", "message": "Sql api is not supported for this database account\\r\\nActivityId: fc5ec296-b7a1- 44df-9c69-42e804177242, Microsoft.Azure.Documents.Common/2.7.0" } { "code": "Forbidden", "message": "此数据库帐户不支持 Sql api\\r\\nActivityId: fc5ec296-b7a1-44df-9c69-42e804177242, Microsoft.Azure.Documents.Common/2.7.0" }
using SDK through the sdk also im getting the same above exception , below is the java code which im using for fetching the documents通过 sdk 使用 SDK 也得到相同的上述异常,下面是我用于获取文档的 java 代码
public class App { private static final String END_POINT = "https://***.documents.azure.com/"; private static final String MASTER_KEY = "***"; // Define an id for your database and collection private static final String DATABASE_ID = "iotdata"; private static final String COLLECTION_ID = "details"; public static void main(String[] args) { DocumentClient documentClient = new DocumentClient(END_POINT, MASTER_KEY, new ConnectionPolicy(), ConsistencyLevel.Session); System.out.println("Check if database " + DATABASE_ID + " exists."); String databaseLink = String.format("/dbs/%s", DATABASE_ID); try { ResourceResponse<Database> readDatabase = documentClient.readDatabase(databaseLink, null); if (readDatabase.getStatusCode() == 200) { System.out.println("Connection Established"); } FeedResponse<Document> queryResults = documentClient.queryDocuments("/dbs/iotdata/colls/details", "SELECT * FROM details WHERE mac_address = '28:b2:bd:01:d0:94'", null); System.out.println("Running SQL query..."); for (Document family : queryResults.getQueryIterable()) { System.out.println(String.format("\\tRead %s", family)); } } catch (Exception e) { e.printStackTrace(); } }
} }
Firstly,i have to say that your sample code in second point is totally right.I tested it and works with Cosmos DB Sql Api.首先,我不得不说你在第二点中的示例代码是完全正确的。我测试了它并与 Cosmos DB Sql Api 一起使用。
According to the error:根据错误:
Sql api is not supported for this database account此数据库帐户不支持 Sql api
It seems that you want to access cosmos db account of other type(maybe mongo api i guess) with SQL API REST API or SQL API SDK.您似乎想使用SQL API REST API或 SQL API SDK 访问其他类型的 cosmos db 帐户(我猜可能是 mongo api)。 That's forbidden and i'm afraid that's the reason for above error.If your Cosmos DB account is using the Mongo API, you should be using tools and drivers that use the Mongo API.这是被禁止的,恐怕这就是上述错误的原因。如果您的 Cosmos DB 帐户使用的是 Mongo API,则您应该使用使用 Mongo API 的工具和驱动程序。 Please refer to this case: Sql api is not supported for this database Error请参考这个案例: Sql api is not supported for this database Error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.