/class-03/class-03-resolved-ajanini-alexandre-reiff-janini.md

https://github.com/Webschool-io/be-mean-instagram-mongodb-exercises · Markdown · 170 lines · 159 code · 11 blank · 0 comment · 0 complexity · 168de215121ec1dfa83ba3a993993529 MD5 · raw file

  1. # MongoDB - Aula 03 - Exercício
  2. autor: Alexandre Reiff Janini
  3. ## 1. Liste todos Pokemons com a altura menor que 0.5;
  4. ```
  5. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> var query = { height: { $lt: 0.5 } }
  6. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query)
  7. {
  8. "_id": ObjectId("5649c4a775dda0a3d275f8dc"),
  9. "name": "Pikachu",
  10. "description": "Whenever Pikachu comes across something new, it blasts it with a jolt of electricity. If you come across a blackened berry, it's evidence that this Pokémon mistook the intensity of its charge. It is the world's most famouse and cute pokemon.",
  11. "type": "electric",
  12. "attack": 55,
  13. "defense": 40,
  14. "height": 0.4
  15. }
  16. {
  17. "_id": ObjectId("5649c4a775dda0a3d275f8df"),
  18. "name": "Pumpkaboo",
  19. "description": "The pumpkin body is inhabited by a spirit trapped in this world. As the sun sets, it becomes restless and active.",
  20. "type": "grass",
  21. "attack": 66,
  22. "defense": 70,
  23. "height": 0.4
  24. }
  25. {
  26. "_id": ObjectId("5649c4a775dda0a3d275f8e1"),
  27. "name": "Zigzagoon",
  28. "description": "Zigzagoon restlessly wanders everywhere at all times. This Pokémon does so because it is very curious. It becomes interested in anything that it happens to see.",
  29. "type": "normal",
  30. "attack": 30,
  31. "defense": 41,
  32. "height": 0.4
  33. }
  34. Fetched 3 record(s) in 3ms
  35. ```
  36. ## 2. Liste todos Pokemons com a altura maior ou igual que 0.5;
  37. ```
  38. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> var query = { height: { $gte: 0.5 } }
  39. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query)
  40. {
  41. "_id": ObjectId("5649c4a775dda0a3d275f8d9"),
  42. "name": "Zekrom",
  43. "description": "This legendary Pokémon can scorch the world with lightning. It assists those who want to build an ideal world.",
  44. "type": "electric",
  45. "attack": 150,
  46. "defense": 120,
  47. "height": 2.9
  48. }
  49. {
  50. "_id": ObjectId("5649c4a775dda0a3d275f8da"),
  51. "name": "Shuckle",
  52. "description": "Shuckle quietly hides itself under rocks, keeping its body concealed inside its hard shell while eating berries it has stored away. The berries mix with its body fluids to become a juice.",
  53. "type": "bug",
  54. "attack": 10,
  55. "defense": 230,
  56. "height": 0.6
  57. }
  58. {
  59. "_id": ObjectId("5649c4a775dda0a3d275f8db"),
  60. "name": "Dewott",
  61. "description": "Strict training is how it learns its flowing double-scalchop technique.",
  62. "type": "water",
  63. "attack": 75,
  64. "defense": 60,
  65. "height": 0.8
  66. }
  67. {
  68. "_id": ObjectId("5649c4a775dda0a3d275f8dd"),
  69. "name": "Serperior",
  70. "description": "It only gives its all against strong opponents who are not fazed by the glare from Serperior's noble eyes.",
  71. "type": "grass",
  72. "attack": 75,
  73. "defense": 95,
  74. "height": 3.3
  75. }
  76. {
  77. "_id": ObjectId("5649c4a775dda0a3d275f8de"),
  78. "name": "Jolteon",
  79. "description": "Jolteon's cells generate a low level of electricity. This power is amplified by the static electricity of its fur, enabling the Pokémon to drop thunderbolts. The bristling fur is made of electrically charged needles.",
  80. "type": "electric",
  81. "attack": 65,
  82. "defense": 60,
  83. "height": 0.8
  84. }
  85. {
  86. "_id": ObjectId("5649c4a775dda0a3d275f8e0"),
  87. "name": "Claydol",
  88. "description": "Claydol are said to be dolls of mud made by primitive humans and brought to life by exposure to a mysterious ray. This Pokémon moves about while levitating.",
  89. "type": "psychic",
  90. "attack": 70,
  91. "defense": 105,
  92. "height": 15
  93. }
  94. {
  95. "_id": ObjectId("5649c4a775dda0a3d275f8e2"),
  96. "name": "Herdier",
  97. "description": "This very loyal Pokémon helps Trainers, and it also takes care of other Pokémon.",
  98. "type": "normal",
  99. "attack": 80,
  100. "defense": 65,
  101. "height": 0.9
  102. }
  103. Fetched 7 record(s) in 4ms
  104. ```
  105. ## 3. Liste todos Pokemons com a altura menor ou igual que 0.5 E do tipo grama;
  106. ```
  107. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> var query = { $and: [ {height: { $lte: 0.5 }}, { type: 'grass' } ] }
  108. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query)
  109. {
  110. "_id": ObjectId("5649c4a775dda0a3d275f8df"),
  111. "name": "Pumpkaboo",
  112. "description": "The pumpkin body is inhabited by a spirit trapped in this world. As the sun sets, it becomes restless and active.",
  113. "type": "grass",
  114. "attack": 66,
  115. "defense": 70,
  116. "height": 0.4
  117. }
  118. Fetched 1 record(s) in 1ms
  119. ```
  120. ## 4. Liste todos Pokemons com o name `Pikachu` OU com attack menor ou igual que 0.5;
  121. ```
  122. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> var query = { $or: [ { name: "Pikachu"}, { attack: { $lte: 0.5 } } ] }
  123. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query)
  124. {
  125. "_id": ObjectId("5649c4a775dda0a3d275f8dc"),
  126. "name": "Pikachu",
  127. "description": "Whenever Pikachu comes across something new, it blasts it with a jolt of electricity. If you come across a blackened berry, it's evidence that this Pokémon mistook the intensity of its charge. It is the world's most famouse and cute pokemon.",
  128. "type": "electric",
  129. "attack": 55,
  130. "defense": 40,
  131. "height": 0.4
  132. }
  133. Fetched 1 record(s) in 0ms
  134. ```
  135. Não qualquer pokemon com attack menor ou igual a 0.5. O menor valor é 10.
  136. ## 5. Liste todos Pokemons com o attack MAIOR OU IGUAL QUE 48 E com height menor ou igual que 0.5;
  137. ```
  138. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> var query = { $and: [ { attack: { $gte: 48 } }, { height: { $lte: 0.5 } } ] }
  139. MacBook-Pro-de-Alexandre(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query)
  140. {
  141. "_id": ObjectId("5649c4a775dda0a3d275f8dc"),
  142. "name": "Pikachu",
  143. "description": "Whenever Pikachu comes across something new, it blasts it with a jolt of electricity. If you come across a blackened berry, it's evidence that this Pokémon mistook the intensity of its charge. It is the world's most famouse and cute pokemon.",
  144. "type": "electric",
  145. "attack": 55,
  146. "defense": 40,
  147. "height": 0.4
  148. }
  149. {
  150. "_id": ObjectId("5649c4a775dda0a3d275f8df"),
  151. "name": "Pumpkaboo",
  152. "description": "The pumpkin body is inhabited by a spirit trapped in this world. As the sun sets, it becomes restless and active.",
  153. "type": "grass",
  154. "attack": 66,
  155. "defense": 70,
  156. "height": 0.4
  157. }
  158. Fetched 2 record(s) in 1ms
  159. ```