Difference between revisions of "AGGREGATE world"
From NoSQLZoo
Line 18: | Line 18: | ||
<div class=q data-lang="py3"> | <div class=q data-lang="py3"> | ||
− | Show the name for the countries that have a population of at least 200 million. | + | Show the name and population for the countries that have a population of at least 200 million. |
<pre class=def> | <pre class=def> | ||
pp.pprint(list( | pp.pprint(list( | ||
Line 26: | Line 26: | ||
<div class=ans> | <div class=ans> | ||
pp.pprint(list( | pp.pprint(list( | ||
− | db.world.find({"population":{"$gt":20000000}},{"name":1,"_id":0}) | + | db.world.find({"population":{"$gt":20000000}},{"name":1,"population":1"_id":0}) |
)) | )) | ||
</div> | </div> | ||
</div> | </div> |
Revision as of 12:01, 16 July 2015
#ENCODING import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16') #MONGO from pymongo import MongoClient client = MongoClient() client.progzoo.authenticate('scott','tiger') db = client['progzoo'] #PRETTY import pprint pp = pprint.PrettyPrinter(indent=4)
Country Profile
For these questions you should use find() on the collection world
Show the name and population for the countries that have a population of at least 200 million.
pp.pprint(list( db.world.find({},{"name":1,"_id":0}) ))
pp.pprint(list(
db.world.find({"population":{"$gt":20000000}},{"name":1,"population":1"_id":0})
))