I have a document structure like:
{ map: 'A', points: [ { type: 'type1', distanceToSpawn: 110 }, { type: 'type4', distanceToSpawn: 40 }, { type: 'type6', distanceToSpawn: 30 } ] }, { map: 'B', points: [ { type: 'type1', distanceToSpawn: 100 }, { type: 'type2', distanceToSpawn: 60 }, { type: 'type3', distanceToSpawn: 25 } ] }, { map: 'C', points: [ { type: 'type2', distanceToSpawn: 90 }, { type: 'type3', distanceToSpawn: 1 }, { type: 'type6', distanceToSpawn: 76 } ] }
I want all the cards to have a type1 point type, sorted by distanceToSpawn in ascending order.
Expected Result:
{ map: 'B', points: [ { type: 'type1', distanceToSpawn: 100 } ] }, { map: 'A', points: [ { type: 'type1', distanceToSpawn: 110 } ] }
I tried something like:
db.maps.find({'points.type': {$eq : 'type1'}}, {map: 1, 'points.$':1}).sort({'points.distanceToSpawn': 1}).limit(10)
But this thing does not sort the cards in ascending order.
Thanks.