在执行collection.count(queryParams);
. 在 Java 中,如何从所有分片/多个分片中读取所有数据?我们正在使用 Microsoft Azure Cosmos DB。
[ERROR] Caused by: com.mongodb.MongoCommandException: Command failed with error 61: 'query in command must target a single shard key' on server ".
示例代码:
MongoCollection<Document> collection = database.getCollection(eventsCollectionName);
Bson queryParams = Filters.and(
Filters.eq("mysystem.name", dmsEvent.getSystem().getName()),
Filters.eq("mysystem.environment", dmsEvent.getSystem().getEnvironment()),
Filters.eq("mymessage.type", dmsEvent.getMessage().getType()),
Filters.eq("myuser.syscode_id", dmsEvent.getUser_id().getSyscode_id()),
Filters.eq("myuser.condition_id", dmsEvent.getUser_id().getCondition_id()));
//This line is erroring out
long recordCount = collection.count(queryParams);
示例 Cosmos DB 收集文档:分片 键是“/partitionKey”。
{
"_id" : ObjectId("5ab85424a43e6b11916ff6c3"),
"myuser" : {
"syscode_id" : 1,
"condition_id" : 1
},
"mysystem" : {
"name" : "4DL",
"environment" : "D"
},
"mymessage" : {
"type" : "A",
"occurance_count" : 1,
"rolltime" : "2018-03-25T18:00Z",
"timestamp" : "2018-03-25T18:00:11.150379Z"
},
"mydata" : {
"count" : "12",
"slot" : [
{
"length" : null,
"value" : "FF00"
}
]
},
"partitionKey" : "18",
"timeToLive" : 777600,
"_ts" : "2018-03-26 02:00:04.495"
}