我正在使用spring data mongodb的分片支持,在文档上添加@sharded注解:
@Sharded(immutableKey = true, shardKey = { "location.locationId", "ts" })
但是,当spring数据生成请求时,添加的过滤器包含:
filterWithShardKey = {Document@20158} size = 3
"_id" -> {ObjectId@20139} "60489730a9687c7c83a287df"
"location.locationId" -> null
"ts" -> {Date@20141} "Mon Feb 17 12:13:06 CET 2020"
我查看了queryoperations类及其applyshardkey方法:
getMappedShardKeyFields(domainType).forEach(key -> filterWithShardKey.putIfAbsent(key, shardKeySource.get(key)));
shardkeysource是一个bson文档,它将嵌套文档也表示为bson文档(不是平面文档)。因此,在获取“location.locationid”字段时,找不到:
documentAsMap = {LinkedHashMap@20083} size = 9
"_id" -> {ObjectId@20099} "60489996721f557bb2c8e5d6"
"ts" -> {Date@20101} "Mon Feb 17 12:13:06 CET 2020"
"location" -> {Document@20103} size = 3
key = "location"
value = {Document@20103} size = 3
"source" -> {Document@20105} size = 7
"device" -> {Document@20107} size = 2
"timezoneRawOffset" -> {Double@20109} 1.0
有没有一种方法可以用spring数据mongodb声明嵌套的切分键?
谢谢你的回答!
暂无答案!
目前还没有任何答案,快来回答吧!