I have a couple of entries for each cities. How to get lastest 3 entries of each city? Like:
City1
record 1
record 2
record 3
City2
record 1
record 2
record 3
City3
record 1
record 2
record 3
The schema:
var schema = mongoose.Schema({
city: {type: String},
title: {type: String},
created: {type: Number, default: Math.floor(new Date() / 1000)}
})
The code I've tried:
Collection
.find('location $in ' + cities)
.aggregate({$group: {location: "$location"}})
.sort('created: 1')
.limit(3).exec(function(err, docs) { res.render('index', { hash: docs }); });
So, how to perform a query where I should have as result: 3 most recent titles of each city