[英]How to fix: Azure Cosmos DB SQL API does not seem to work
I'm currently involved with a migration from a MongoDB instance to a Azure Cosmos DB instance. 我目前正在参与从MongoDB实例迁移到Azure Cosmos数据库实例。 Because of this I am throwing out the mongo-java-driver dependency and replacing it with the latest azure-documentdb (version 2.4.0) dependency. 因此,我抛弃了mongo-java-driver依赖项并将其替换为最新的azure-documentdb(版本2.4.0)依赖项。
I have a trips
collection in my foobar
Azure Cosmos database with the following document structure: 我在我的foobar
Azure Cosmos数据库中有一个trips
集合,其中包含以下文档结构:
{
"_id" : ObjectId("5d0cdd6a6b1bb358985eb5d5"),
"od" : 1561075200000,
"rid" : "d001",
"tnr" : 1007,
"rsn" : 0,
"p" : [
{
"s" : 1,
"st" : "P",
"sid" : "18003100",
},
{...}
]
}
The first thing I've tried for this migration project is to query my trips collection with a simple where statement which is codewise pretty much the same as in a example found here: https://github.com/Azure/azure-documentdb-java/ 我为这个迁移项目尝试的第一件事就是使用一个简单的where语句来查询我的trip集合,该语句的代码与这里的示例非常相似: https : //github.com/Azure/azure-documentdb-的Java /
The problem is as follows. 问题如下。 When I try to query the trips collection for documents where rid
equals to d001
it gives back zero results with the following code. 当我尝试查询trip集合中的rid
等于d001
文档时,它会使用以下代码返回零结果。 That shouldn't be the case since I have 9 matching documents in my trips collection. 不应该是这种情况,因为我的旅行集合中有9个匹配的文件。
DocumentClient client = new DocumentClient(
HOST,
MASTER_KEY,
ConnectionPolicy.GetDefault(),
ConsistencyLevel.Session);
FeedOptions feedOptions = new FeedOptions();
FeedResponse<Document> query = client.queryDocuments(
"dbs/foobar/colls/trips",
"SELECT * FROM trips t WHERE t.rid='d001'",
feedOptions);
List<Document> results = query.getQueryIterable().toList();
System.out.println(results.size());
Also changing the query to "SELECT t.rid FROM trips t"
gives back zero results. 同时将查询更改为"SELECT t.rid FROM trips t"
会返回零结果。 Also changing the query to "SELECT * FROM trips t WHERE t['rid']='d001'"
gives back zero results. 同时将查询更改为"SELECT * FROM trips t WHERE t['rid']='d001'"
返回零结果。
When I change the query to "SELECT * FROM trips t"
everything seems just fine and it returns all documents in the collection. 当我将查询更改为"SELECT * FROM trips t"
一切似乎都很好,它会返回集合中的所有文档。
What could be the problem here? 这可能是什么问题?
Try with the following query, 尝试使用以下查询,
FeedResponse<Document> query = client.queryDocuments(
"dbs/foobar/colls/trips",
"SELECT * FROM trips t WHERE t.rid='d001'",
null).toBlocking().first();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.