MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Mongodb e sottoarray di ordinamento

Sorprendentemente, sì, mongodb può farlo:

// Sort ascending, by minimum percentage value in the docs' offers array.
db.collection.find({}).sort({ 'offers.percentage': 1 });

// Sort descending, by maximum percentage value in the docs' offers array.
db.collection.find({}).sort({ 'offers.percentage': -1 });