pokemon.json/pokedex.json at master · fanzeyi/pokemon.json
Find all the Pokemon and limit the displayed documents to 10
pokemon.find({}).limit(10)
Find all Pokémon with a base attack greater than or equal to 50, limiting the results to show only 10
pokemon.find({'base.Attack': {'$gte': 50}}).limit(10)
Find all pokemons with base attack greater than or equal to 50 limiting the results to 10. In this case project only the base stats and all the names (written in all languages)
pokemon.find({'base.Attack': {'$gte': 50}}, {'base': 1, "name": 1}).limit(10)
Find all pokemons with base defense less than 90 or type "Flying" (check only for "Flying" in the type array). In this case project only the base attack, the english name and the types. Limit results to 20
pokemon.find({
'$or': [
{'base.Defense': {'$lt': 90}},
{"type": "Flying"}
]
},
{
'_id':0, 'name.english':1,'base.Attack': 1,'type': 1
}).limit(20)
Find pokemons with 4 types or pokemons of type Flying
pokemon.find({
'$or': [
{"type": {"$size": 4}},
{"type": {'$elemMatch': {'$eq': 'Fighting'}}}
]
})
Find all pokemons that begins with the substring "Char", projecting only english and japanese names
pokemon.find({
'name.english': {'$regex': '^Char'}
}, {'name.english': 1, 'name.japanese': 1})
Find the first pokemon with base stats: {"HP" : 75, "Attack" : 98, "Defense" : 63, "Sp. Attack" : 98, "Sp. Defense" : 63, "Speed" : 101}
pokemon.find_one({'base': {
"HP" : 75,
"Attack" : 98,
"Defense" : 63,
"Sp. Attack" : 98,
"Sp. Defense" : 63,
"Speed" : 101
}})
Using the aggregate pipeline, find all pokemons with base attack greater than 50 and of type “Grass” and “Poison”
pokemon.aggregate([
{
'$match': {
"base.Attack": {"$gt": 50},
"type": {"$all": ["Grass", "Poison"]}
}
},
{
"$project": {
"_id": 0,
"name.english": 1,
"name.japanese": 1,
"base.Attack": 1,
"type": 1,
}
},
])
Using the aggregate pipeline, find all pokemons with base attack greater than 50 and of type “Grass” and “Poison” sorting result by base attack in descending order, projecting only english name, japanese name, base attack and types
pokemon.aggregate([{
"$match": {
"base.Attack": {"$gt": 50},
"type": {"$all": ["Grass", "Poison"]}
}
}, {
"$project": {
"_id": 0,
"name.english": 1,
"name.japanese": 1,
"base.Attack": 1,
"type": 1
}
}, {
"$sort": {"base.Attack": -1}
}])
Using the aggregate pipeline, find the sum of the base attack of all the pokemons with base attack greater than 50 and of type “Grass” and “Poison”
pokemon.aggregate([{
"$match": {
"base.Attack": {"$gt": 50},
"type": {"$all": ["Grass", "Poison"]}
}
}, {
"$group": {
"_id": "The sum of Attack greater than 50",
"sum rating": {
"$sum": "$base.Attack"
}
}
}])
Using the aggregate pipeline, find the avg of the base attack of pokemons grouped by types
pokemon.aggregate([{
"$match": {
"base.Attack": {"$gt": 50},
}
}, {
"$group": {
"_id": "$type",
"avg types": {
"$avg": "$base.Attack"
}
}
}])