/class-03/class-03-resolved-adrpnt-adriano-vasconcelos.md

https://gitlab.com/BelinhaIsis/be-mean-instagram-mongodb-exercises · Markdown · 226 lines · 220 code · 6 blank · 0 comment · 0 complexity · 4a7e2a043b69dd3002fca431020272ed MD5 · raw file

  1. # MongoDB - Aula 01 - Exercício
  2. autor: ADRIANO VASCONCELOS
  3. ## Liste todos Pokemons
  4. ```
  5. db.pokemons.find();
  6. {
  7. "_id": ObjectId("564379f8750d5acfe9690da9"),
  8. "name": "Butterfree",
  9. "description": "In battle, it flaps its wings at high speed to release highly toxic dust into the air.",
  10. "type": "inseto",
  11. "attack": 45,
  12. "defense": 50,
  13. "height": 0.3,
  14. "heigth": 0.3
  15. }
  16. {
  17. "_id": ObjectId("56437b1d750d5acfe9690daa"),
  18. "name": "Arbok",
  19. "description": "The frightening patterns on its belly have been studied. Six variations have been confirmed.",
  20. "type": "veneno",
  21. "attack": 85,
  22. "defense": 69,
  23. "height": 0.9
  24. }
  25. {
  26. "_id": ObjectId("56437bb5750d5acfe9690dab"),
  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("56437c43750d5acfe9690dac"),
  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("56437cbb750d5acfe9690dad"),
  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("56437e14750d5acfe9690daf"),
  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("56437e14750d5acfe9690db0"),
  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. Fetched 7 record(s) in 6ms
  71. ```
  72. ## Liste todos Pokemons com a altura menor que 0.5;
  73. ```
  74. var query = {"height": {$lt : 0.5}};
  75. vagrant-ubuntu-trusty-64(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query);
  76. {
  77. "_id": ObjectId("564379f8750d5acfe9690da9"),
  78. "name": "Butterfree",
  79. "description": "In battle, it flaps its wings at high speed to release highly toxic dust into the air.",
  80. "type": "inseto",
  81. "attack": 45,
  82. "defense": 50,
  83. "height": 0.3,
  84. "heigth": 0.3
  85. }
  86. {
  87. "_id": ObjectId("56437bb5750d5acfe9690dab"),
  88. "name": "Ninetales",
  89. "description": "Its nine tails are said to be imbued with a mystic power. It can live for a thousand years.",
  90. "type": "fogo",
  91. "attack": 76,
  92. "defense": 75,
  93. "height": 0.3
  94. }
  95. {
  96. "_id": ObjectId("56437c43750d5acfe9690dac"),
  97. "name": "Grimer",
  98. "description": "Appears in filthy areas. Thrives by sucking up polluted sludge that is pumped out of factories.",
  99. "type": "veneno",
  100. "attack": 80,
  101. "defense": 50,
  102. "height": 0.2
  103. }
  104. {
  105. "_id": ObjectId("56437cbb750d5acfe9690dad"),
  106. "name": "Dewgong",
  107. "description": "Stores thermal energy in its body. Swims at a steady 8 knots even in intensely cold waters.",
  108. "type": "água",
  109. "attack": 70,
  110. "defense": 80,
  111. "height": 0.4
  112. }
  113. {
  114. "_id": ObjectId("56437e14750d5acfe9690daf"),
  115. "name": "Beedrill",
  116. "description": "It can take down any opponent with its powerful poi son stingers.",
  117. "type": "inseto",
  118. "attack": 90,
  119. "defense": 40,
  120. "height": 0.2
  121. }
  122. {
  123. "_id": ObjectId("56437e14750d5acfe9690db0"),
  124. "name": "Nidorina",
  125. "description": "When NIDORINA are with their friends or family, they keep their barbs tucked away to prevent hurting each other.",
  126. "type": "veneno",
  127. "attack": 62,
  128. "defense": 67,
  129. "height": 0.2
  130. }
  131. Fetched 6 record(s) in 1ms
  132. ```
  133. ## Liste todos Pokemons com a altura maior ou igual que 0.5;
  134. ```
  135. var query = {"height": {$gte : 0.5}};
  136. vagrant-ubuntu-trusty-64(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query);
  137. {
  138. "_id": ObjectId("56437b1d750d5acfe9690daa"),
  139. "name": "Arbok",
  140. "description": "The frightening patterns on its belly have been studied. Six variations have been confirmed.",
  141. "type": "veneno",
  142. "attack": 85,
  143. "defense": 69,
  144. "height": 0.9
  145. }
  146. Fetched 1 record(s) in 1ms
  147. ```
  148. ## Liste todos Pokemons com a altura menor ou igual que 0.5 E do tipo grama;
  149. ```
  150. var query = {$and: [{"height": {$lte : 0.5}}, {"type": "grama"}]};
  151. vagrant-ubuntu-trusty-64(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query);
  152. Fetched 0 record(s) in 0ms
  153. ```
  154. ## Liste todos Pokemons com o name `Pikachu` OU com attack menor ou igual que 48;
  155. ```
  156. var query = {$or: [{"name": "Pikachu"}, {"attack": {$lte: 48}}]};
  157. vagrant-ubuntu-trusty-64(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query);
  158. {
  159. "_id": ObjectId("564379f8750d5acfe9690da9"),
  160. "name": "Butterfree",
  161. "description": "In battle, it flaps its wings at high speed to release highly toxic dust into the air.",
  162. "type": "inseto",
  163. "attack": 45,
  164. "defense": 50,
  165. "height": 0.3,
  166. "heigth": 0.3
  167. }
  168. Fetched 1 record(s) in 1ms
  169. ```
  170. ## Liste todos Pokemons com o attack MAIOR OU IGUAL QUE 48 E com height menor ou igual que 0.5;
  171. ```
  172. var query = {$and: [{"height": {$lte : 0.5}}, {"attack": {$gte: 48}}]};
  173. vagrant-ubuntu-trusty-64(mongod-3.0.7) be-mean-pokemons> db.pokemons.find(query);
  174. {
  175. "_id": ObjectId("56437bb5750d5acfe9690dab"),
  176. "name": "Ninetales",
  177. "description": "Its nine tails are said to be imbued with a mystic power. It can live for a thousand years.",
  178. "type": "fogo",
  179. "attack": 76,
  180. "defense": 75,
  181. "height": 0.3
  182. }
  183. {
  184. "_id": ObjectId("56437c43750d5acfe9690dac"),
  185. "name": "Grimer",
  186. "description": "Appears in filthy areas. Thrives by sucking up polluted sludge that is pumped out of factories.",
  187. "type": "veneno",
  188. "attack": 80,
  189. "defense": 50,
  190. "height": 0.2
  191. }
  192. {
  193. "_id": ObjectId("56437cbb750d5acfe9690dad"),
  194. "name": "Dewgong",
  195. "description": "Stores thermal energy in its body. Swims at a steady 8 knots even in intensely cold waters.",
  196. "type": "água",
  197. "attack": 70,
  198. "defense": 80,
  199. "height": 0.4
  200. }
  201. {
  202. "_id": ObjectId("56437e14750d5acfe9690daf"),
  203. "name": "Beedrill",
  204. "description": "It can take down any opponent with its powerful poi son stingers.",
  205. "type": "inseto",
  206. "attack": 90,
  207. "defense": 40,
  208. "height": 0.2
  209. }
  210. {
  211. "_id": ObjectId("56437e14750d5acfe9690db0"),
  212. "name": "Nidorina",
  213. "description": "When NIDORINA are with their friends or family, they keep their barbs tucked away to prevent hurting each other.",
  214. "type": "veneno",
  215. "attack": 62,
  216. "defense": 67,
  217. "height": 0.2
  218. }
  219. Fetched 5 record(s) in 7ms
  220. ```