0

I have database collection like this

Fruit class

_iD

country

listNameFruit

    Mango ,
    Tomato,
    Apple

So I have class named Fruit and FruitName , inside Fruit.class I have list<FruitName> , so I want to get my Fruit and list of FruitName sort by ascending

Here's my code to get the collection

MongoOperations mongoOps;

Query query = ???
mongoOps.findOne(query, Fruit.class);

I want to get my fruit data but I want the listNameFruit is sort by ascending , what should i write in the query so i can get my list sort by ascending ?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Alnov Lucky
  • 35
  • 1
  • 9
  • What are you actually searching for? You've said `findOne` so presumably you're looking for a specific fruit, is that by ID, by country, or just the first value you can find? – Trisha Aug 14 '15 at 13:16
  • Also, I don't think that MongoDB allows you to sort the values in an array in a straightforward fashion - they are returned in the same order they are stored in the database. You can [change this order when writing to the list](http://docs.mongodb.org/v2.6/reference/operator/update/sort/#up._S_sort), but when querying you might need to look at the Aggregation Framework. An example is here: http://stackoverflow.com/questions/13449874/how-to-sort-array-inside-collection-record-in-mongodb – Trisha Aug 14 '15 at 13:29

0 Answers0