## Project Results 

"Code": "DEU", "Name": "Germany", "IndepYear": 1955, "geography": { "Region": "Western Europe", "Continent": "Europe", "SurfaceArea": 357022 }, "government": { "HeadOfState": "Johannes Rau", "GovernmentForm": "Federal Republic" }, "demographics": { "Population": 82164700, "LifeExpectancy": 77.4000015258789 } } 1 document in set (0.0026 sec) 

You can return specific fields of a document, instead of returning all the fields. The following example returns the GNP and Name fields of all documents in the countryinfo  collection matching the search conditions. 

Use the fields()  method to pass the list of fields to return. 

mysql-js> db.countryinfo.find("GNP > 5000000").fields(["GNP", "Name"]) [ { "GNP": 8510700, "Name": "United States" } ] 1 document in set (0.00 sec) 

In addition, you can alter the returned documents—adding, renaming, nesting and even computing new field values—with an expression that describes the document to return. For example, alter the names of the fields with the following expression to return only two documents. 

mysql-js> db.countryinfo.find().fields( mysqlx.expr(’{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}’)).limit(2) { "Name": "ARUBA", "GNPPerCapita": 8038.834951456311 } { "Name": "AFGHANISTAN", "GNPPerCapita": 263.0281690140845 } 

## Limit, Sort, and Skip Results 

You can apply the limit() , sort() , and skip()  methods to manage the number and order of documents returned by the find()  method. 

To specify the number of documents included in a result set, append the limit()  method with a value to the find()  method. The following query returns the first five documents in the countryinfo  collection. 

mysql-js> db.countryinfo.find().limit(5) ... [ output removed ] 5 documents in set (0.00 sec) 

