I would like to do this using MongoDB aggregation-framework, is this possible?
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}}
]);
Is this possible to do this with db.collection.group({ key, reduce, initial [, keyf] [, cond] [, finalize] }) ?...
$andoperator on the first$match, the two conditions are in$andby default. Just write$match: { location: { ... }, date1: { ... } }. Also in your$projectyou must defineratioas an object key:$project: { ratio: {$divide ... } }.