【发布时间】:2021-02-13 01:39:50
【问题描述】:
我们有以下数据:
[
{
"location" : {
"type" : "POINT",
"coordinates" : [
-92.41151,
35.11683
]
},
"geoHash" : "dr72jwgnbbst"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-89.58342,
36.859161
]
},
"geoHash" : "dn6qtkr5xk8m"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-86.038762,
36.519016
]
},
"geoHash" : "dn6zf0h6xtcp"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-98.3081936,
26.2143207
]
},
"geoHash" : "9udj4unjmp9f"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-98.5377275,
29.4878928
]
},
"geoHash" : "9v1zv8p52t8u"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-73.7018126,
42.641387
]
},
"geoHash" : "dreddfeup69m"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-111.865295,
33.431942
]
},
"geoHash" : "9tbqnqn5jtwq"
},
{
"location" : {
"type" : "POINT",
"coordinates" : [
-79.810763,
34.174603
]
},
"geoHash" : "dnp4rv796rtz"
}]
我们需要一个查询来获取以“dn”、“9t”、“dr”、“9v”、“9u”开头的地理哈希的位置,并且每个地理哈希只应返回一个位置。例如,我们有 3 个位置的 geohash 以“dn”开头,但它应该只返回任何一个位置。 输出:
"dr" -> "location" : {
"type" : "POINT",
"coordinates" : [
-92.41151,
35.11683
]
}
"dn" -> "location" : {
"type" : "POINT",
"coordinates" : [
-89.58342,
36.859161
]
}
"9u" -> "location" : {
"type" : "POINT",
"coordinates" : [
-98.3081936,
26.2143207
]
}
"9v" -> "location" : {
"type" : "POINT",
"coordinates" : [
-98.5377275,
29.4878928
]
}
"9t" -> "location" : {
"type" : "POINT",
"coordinates" : [
-111.865295,
33.431942
]
}
谢谢
【问题讨论】:
标签: mongodb mongodb-query spring-data-mongodb