I have a collection called at MongoDB called resource. It has the following documents:
{ \"_id\" : \"Abb.e\", \"_class\" : \"Resource\", \"resourceEmail\" :
Should be something like this:
MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate();
List resourceList = mongoOperations.findAll(Resource.class).sort({'_id' : 1});
return resourceList;
You need to append .sort({'_id' : 1})
for ascending order
or .sort({'_id' : -1})
for descending order.
For Java:
.sort( new BasicDBObject( "_id" , 1 ) )
Solution from echo:
DBCursor dbCursor = mongoOperations.getCollection(RESOURCE_COLLECTION_NAME).find().sort(new BasicDBObject("_id", 1));
List dbObjects = dbCursor.toArray();
List