To specify an order for the results, append the sort()  method to the find()  method. Pass to the sort()  method a list of one or more fields to sort by and, optionally, the descending ( desc ) or ascending ( asc ) attribute as appropriate. Ascending order is the default order type. 

For example, the following query sorts all documents by the IndepYear field and then returns the first eight documents in descending order. 

mysql-py> db.countryinfo.find().sort(["IndepYear desc"]).limit(8) ... [ output removed ] 8 documents in set (0.00 sec) 

By default, the limit()  method starts from the first document in the collection. You can use the skip() method to change the starting document. For example, to ignore the first document and return the next eight documents matching the condition, pass to the skip()  method a value of 1. 

## Related Information 

mysql-py> db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1) ... [ output removed ] 8 documents in set (0.00 sec) 

•The MySQL Reference Manual provides detailed documentation on functions and operators. 

## 20.4.3.4 Modify Documents 

•See CollectionFindFunction for the full syntax definition. 

You can use the modify()  method to update one or more documents in a collection. The X DevAPI provides additional methods for use with the modify()  method to: 

## Set and Unset Document Fields 

•Set and unset fields within documents. 

•Append, insert, and delete arrays. 

•Bind, limit, and sort the documents to be modified. 

The modify()  method works by filtering a collection to include only the documents to be modified and then applying the operations that you specify to those documents. 

In the following example, the modify()  method uses the search condition to identify the document to change and then the set()  method replaces two values within the nested demographics object. 

mysql-py> db.countryinfo.modify("Code = ’SEA’").set( "demographics", {"LifeExpectancy": 78, "Population": 28}) 

After you modify a document, use the find()  method to verify the change. 

To remove content from a document, use the modify()  and unset()  methods. For example, the following query removes the GNP from a document that matches the search condition. 

mysql-py> db.countryinfo.modify("Name = ’Sealand’").unset("GNP") 

Use the find()  method to verify the change. 

mysql-py> db.countryinfo.find("Name = ’Sealand’") { "_id": "00005e2ff4af00000000000000f4", "Name": "Sealand", 

