이 데이터가 있습니다.
{ "_id" : ObjectId("5ff9227f0c7f5b1601fcceeb"), "geoHash" : "dr72zc5v7440", "customerId" : "abcd"}
{ "_id" : ObjectId("5ff9227f0c7f5b1601fcceec"), "geoHash" : "dr7965kev5r7", "customerId" : "abcd" }
{ "_id" : ObjectId("5ff9227f0c7f5b1601fcceed"), "geoHash" : "dr79umt6rksy", "customerId" : "abcd" }
{ "_id" : ObjectId("5ff9227f0c7f5b1601fcceee"), "geoHash" : "dr7dqxy2cw43", "customerId" : "abcd" }
{ "_id" : ObjectId("5ff9227f0c7f5b1601fcceef"), "geoHash" : "dr7g0czp7xrt", "customerId" : "abcd"}
{ "_id" : ObjectId("5ff9227f0c7f5b1601fccef0"), "geoHash" : "dr7gehpyjbv0", "customerId" : "abcd"}
{ "_id" : ObjectId("5ff9227f0c7f5b1601fccef1"), "geoHash" : "dr7ujw2u8447", "customerId" : "abcd"}
{ "_id" : ObjectId("5ff9227f0c7f5b1601fccef2"), "geoHash" : "dr7uzb9e45ry", "customerId" : "abcd" }
{ "_id" : ObjectId("5ff9227f0c7f5b1601fccef3"), "geoHash" : "drkj64f3skv6", "customerId" : "abcd" }
{ "_id" : ObjectId("5ff9227f0c7f5b1601fccef4"), "geoHash" : "drkjum50nw4t", "customerId" : "abcd" }
Mongo db 쿼리 :
db.test.aggregate([{ $match : { "customerId" : "abcd" } }, { "$group": { "_id": {$substr:["$geoHash",0,4]},count: { $sum: 1 } }} ])
이 쿼리를 Spring mongo Java 코드로 어떻게 변환합니까? 아래는 작동하지 않습니다.
AggregationOperation group = Aggregation.group("geoHash")
.first(StringOperators.Substr.valueOf("geoHash").substring(0, 4))
.as("geoHash")
.count().as("geoHashCount");