/class-03/class-03-resolved-thiagobitencourt-Thiago-Bitencourt.md

https://github.com/Webschool-io/be-mean-instagram-mongodb-exercises · Markdown · 208 lines · 203 code · 5 blank · 0 comment · 0 complexity · b190f4c39432db45af90f08c90275cc3 MD5 · raw file

  1. # MongoDB - Aula 03 - Exercício
  2. autor: Thiago R. M. Bitencourt
  3. ## 1. Pokemons com altura menor que 0.5
  4. ```
  5. > var query = {height: {$lt: 0.5}}
  6. > db.pokemons.find(query).pretty()
  7. {
  8. "_id" : ObjectId("5779c658ebea693787997606"),
  9. "name" : "Vulpix",
  10. "description" : "Fofo porém mortal",
  11. "type" : "fogo",
  12. "attack" : 41,
  13. "height" : 0.4
  14. }
  15. {
  16. "_id" : ObjectId("577b1901fe6950263ad63a64"),
  17. "name" : "Butterfree",
  18. "description" : "In battle, it flaps its wings at high speed to release highly toxic dust into the air.",
  19. "type" : "inseto",
  20. "attack" : 45,
  21. "defense" : 50,
  22. "height" : 0.3,
  23. "heigth" : 0.3
  24. }
  25. {
  26. "_id" : ObjectId("577b1901fe6950263ad63a66"),
  27. "name" : "Ninetales",
  28. "description" : "Its nine tails are said to be imbued with a mystic power. It can live for a thousand years.",
  29. "type" : "fogo",
  30. "attack" : 76,
  31. "defense" : 75,
  32. "height" : 0.3
  33. }
  34. {
  35. "_id" : ObjectId("577b1901fe6950263ad63a67"),
  36. "name" : "Grimer",
  37. "description" : "Appears in filthy areas. Thrives by sucking up polluted sludge that is pumped out of factories.",
  38. "type" : "veneno",
  39. "attack" : 80,
  40. "defense" : 50,
  41. "height" : 0.2
  42. }
  43. {
  44. "_id" : ObjectId("577b1901fe6950263ad63a68"),
  45. "name" : "Dewgong",
  46. "description" : "Stores thermal energy in its body. Swims at a steady 8 knots even in intensely cold waters.",
  47. "type" : "água",
  48. "attack" : 70,
  49. "defense" : 80,
  50. "height" : 0.4
  51. }
  52. {
  53. "_id" : ObjectId("577b1901fe6950263ad63a69"),
  54. "name" : "Beedrill",
  55. "description" : "It can take down any opponent with its powerful poi son stingers.",
  56. "type" : "inseto",
  57. "attack" : 90,
  58. "defense" : 40,
  59. "height" : 0.2
  60. }
  61. {
  62. "_id" : ObjectId("577b1901fe6950263ad63a6a"),
  63. "name" : "Nidorina",
  64. "description" : "When NIDORINA are with their friends or family, they keep their barbs tucked away to prevent hurting each other.",
  65. "type" : "veneno",
  66. "attack" : 62,
  67. "defense" : 67,
  68. "height" : 0.2
  69. }
  70. ```
  71. ## 2. Pokemons com a altura maior ou igual que 0.5
  72. ```
  73. > var query = {height: {$gte : 0.5}}
  74. > db.pokemons.find(query).pretty()
  75. {
  76. "_id" : ObjectId("5779c63eebea693787997603"),
  77. "name" : "Charizard",
  78. "description" : "Pokemon massa de fogo",
  79. "type" : "fogo",
  80. "attack" : 77,
  81. "height" : 1.7
  82. }
  83. {
  84. "_id" : ObjectId("5779c64bebea693787997604"),
  85. "name" : "Pidgeot",
  86. "description" : "Voador dos bons",
  87. "type" : "voador",
  88. "attack" : 69,
  89. "height" : 1.5
  90. }
  91. {
  92. "_id" : ObjectId("5779c650ebea693787997605"),
  93. "name" : "Persian",
  94. "description" : "Gatinho mortal",
  95. "type" : "Fancy cat",
  96. "attack" : 94,
  97. "height" : 1.1
  98. }
  99. {
  100. "_id" : ObjectId("5779c65debea693787997607"),
  101. "name" : "Zubat",
  102. "description" : "Parente distante do batman",
  103. "type" : "Batman",
  104. "attack" : 38,
  105. "height" : 0.8
  106. }
  107. {
  108. "_id" : ObjectId("577b1901fe6950263ad63a65"),
  109. "name" : "Arbok",
  110. "description" : "The frightening patterns on its belly have been studied. Six variations have been confirmed.",
  111. "type" : "veneno",
  112. "attack" : 85,
  113. "defense" : 69,
  114. "height" : 0.9
  115. }
  116. ```
  117. ## 3. Pokemons com a altura maior ou igual que 0.5 e do tipo grama
  118. ```
  119. > var query = {$end: [{height: {$gte : 0.5}}, {type: "grama"}]}
  120. > db.pokemons.find(query)
  121. >
  122. ```
  123. ## 4. Pokemons com o name 'Pikachu' ou com attack menor ou igual que 50;
  124. ```
  125. > var query = {$or: [{name: "Pikachu"}, {attack: {$lte: 50}}]}
  126. > db.pokemons.find(query).pretty()
  127. {
  128. "_id" : ObjectId("5779c658ebea693787997606"),
  129. "name" : "Vulpix",
  130. "description" : "Fofo porém mortal",
  131. "type" : "fogo",
  132. "attack" : 41,
  133. "height" : 0.4
  134. }
  135. {
  136. "_id" : ObjectId("5779c65debea693787997607"),
  137. "name" : "Zubat",
  138. "description" : "Parente distante do batman",
  139. "type" : "Batman",
  140. "attack" : 38,
  141. "height" : 0.8
  142. }
  143. {
  144. "_id" : ObjectId("577b1901fe6950263ad63a64"),
  145. "name" : "Butterfree",
  146. "description" : "In battle, it flaps its wings at high speed to release highly toxic dust into the air.",
  147. "type" : "inseto",
  148. "attack" : 45,
  149. "defense" : 50,
  150. "height" : 0.3,
  151. "heigth" : 0.3
  152. }
  153. ```
  154. ## 5. Pokemons com attack MAIOR OU IGUAL QUE 48 E com height menor ou igual que 0.5
  155. ```
  156. > var query = {$and: [{attack: {$gte: 48}}, {height: {$lte: 0.5}}]}
  157. > db.pokemons.find(query).pretty()
  158. {
  159. "_id" : ObjectId("577b1901fe6950263ad63a66"),
  160. "name" : "Ninetales",
  161. "description" : "Its nine tails are said to be imbued with a mystic power. It can live for a thousand years.",
  162. "type" : "fogo",
  163. "attack" : 76,
  164. "defense" : 75,
  165. "height" : 0.3
  166. }
  167. {
  168. "_id" : ObjectId("577b1901fe6950263ad63a67"),
  169. "name" : "Grimer",
  170. "description" : "Appears in filthy areas. Thrives by sucking up polluted sludge that is pumped out of factories.",
  171. "type" : "veneno",
  172. "attack" : 80,
  173. "defense" : 50,
  174. "height" : 0.2
  175. }
  176. {
  177. "_id" : ObjectId("577b1901fe6950263ad63a68"),
  178. "name" : "Dewgong",
  179. "description" : "Stores thermal energy in its body. Swims at a steady 8 knots even in intensely cold waters.",
  180. "type" : "água",
  181. "attack" : 70,
  182. "defense" : 80,
  183. "height" : 0.4
  184. }
  185. {
  186. "_id" : ObjectId("577b1901fe6950263ad63a69"),
  187. "name" : "Beedrill",
  188. "description" : "It can take down any opponent with its powerful poi son stingers.",
  189. "type" : "inseto",
  190. "attack" : 90,
  191. "defense" : 40,
  192. "height" : 0.2
  193. }
  194. {
  195. "_id" : ObjectId("577b1901fe6950263ad63a6a"),
  196. "name" : "Nidorina",
  197. "description" : "When NIDORINA are with their friends or family, they keep their barbs tucked away to prevent hurting each other.",
  198. "type" : "veneno",
  199. "attack" : 62,
  200. "defense" : 67,
  201. "height" : 0.2
  202. }
  203. ```