INNER CODE UNIT · JavaScript
printCheapestSuburbs
mongodb-developer/nodejs-quickstart · aggregation.js:43
async function printCheapestSuburbs(client, country, market, maxNumberToPrint) {
const pipeline = [
{
'$match': {
'bedrooms': 1,
'address.country': country,
'address.market': market,
'address.suburb': {
'$exists': 1,
'$ne': ''
},
'room_type': 'Entire home/apt'
}
}, {
'$group': {
'_id': '$address.suburb',
'averagePrice': {
'$avg': '$price'