我有这样的集合
lat long band_1
20.4335456 72.2345456 34
21.54355 72.21256 42
等等
我想要这样的查询
select avg(band_1) from demo where lat <=19.4533 and lat >=21.454 and long <=69.5454 and long >=71.2443
我不知道如何在mongoDB中这样查询
我尝试了什么
db.demo.aggregate([
{ "$group": {
"longitude" : {"$gte":73.83152067661285,"$lte":73.83841931819916},
"latitude" :{"$gte":20.19826172705546,"$lte":20.201649925580337}
},
{
"band_4" : { "$avg" : "$band_4"}
}
}
答案 0 :(得分:1)
试试这个:
db.collection.aggregate([
{$match : {
$and : [
{"lat" : {$gt : 19}},
{"lat" : {$lt : 22}},
{"long" : {$gt : 70}},
{"long" : {$lt : 90}}
]
}},
{$group : {
_id : null,
averageband : {$avg : "$band_1"}
}}
])