我想使用MongoDB聚合框架来做到这一点,这可能吗?
db.objects.aggregate([
{$match:
{$and:[
{location:{$nearSphere:{$geometry:{type:"Point",coordinates:[latitude, longitude]},$minDistance:x,$maxDistance:y}}},
{date1:{$gte:date2}
]
}
},
{$project:ratio
{$divide:[
{$subtract:[date1,date2]},
{result of a function returning distance between this location and latitude, longitude in parameters}
]
}
},
{$sort:{ratio:-1}}
]);
是否可以通过db.collection.group({key,reduce,initial [,keyf] [,cond] [,finalize]})来做到这一点?...