Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. {
  2. "Sigle_1": "BIOS",
  3. "Sigle_2": "BFTA"
  4. },
  5. {
  6. "Sigle_1": "BERP",
  7. "Sigle_2": "BEST"
  8. },
  9. {
  10. "Sigle_1": "BHDL",
  11. "Sigle_2": "BIOS"
  12. },
  13. {
  14. "Sigle_1": "BIPM",
  15. "Sigle_2": "BEST"
  16. },
  17. {
  18. "Sigle_1": "BHDL",
  19. "Sigle_2": "BIOS"
  20. }
  21.  
  22. {
  23. "Sigle": "BIOS",
  24. },
  25. {
  26. "Sigle": "BFTA",
  27. },
  28. {
  29. "Sigle": "BERP",
  30. },
  31. {
  32. "Sigle": "BEST",
  33. },
  34. {
  35. "Sigle": "BHDL",
  36. },
  37. {
  38. "Sigle": "BIPM",
  39. }
  40.  
  41. db.users.aggregate([{$group: {_id: {Sigle1: '$Sigle_1', Sigle2: '$Sigle_2'}}}])
  42.  
  43. db.collection.aggregate([
  44. { "$facet": {
  45. "array1": [
  46. { "$group": {
  47. "_id": "$Sigle_1"
  48. }}
  49. ],
  50. "array2": [
  51. { "$group": {
  52. "_id": "$Sigle_2"
  53. }}
  54. ]
  55. }},
  56. { "$addFields": {
  57. "data": {
  58. "$concatArrays": ["$array1", "$array2"]
  59. }
  60. }},
  61. { "$unwind": "$data" },
  62. { "$replaceRoot": { "newRoot": "$data" }},
  63. { "$group": {
  64. "_id": "$_id"
  65. }},
  66. { "$project": { "Sigle": "$_id", "_id": 0 }}
  67. ])
  68.  
  69. [
  70. {
  71. "Sigle": "BFTA"
  72. },
  73. {
  74. "Sigle": "BEST"
  75. },
  76. {
  77. "Sigle": "BHDL"
  78. },
  79. {
  80. "Sigle": "BERP"
  81. },
  82. {
  83. "Sigle": "BIPM"
  84. },
  85. {
  86. "Sigle": "BIOS"
  87. }
  88. ]
  89.  
  90. {
  91. "Sigle_1": "BIOS",
  92. "Sigle_2": "BFTA",
  93. "Name_1": "Basic Input Output System",
  94. "Name_2": "Belgian Food Truck Association"
  95.  
  96. },
  97. {
  98. "Sigle_1": "BERP",
  99. "Sigle_2": "BEST",
  100. "Name_1": "British Experimental Rotor Programme",
  101. "Name_2": "Board of European Students of Technology"
  102. },
  103. {
  104. "Sigle_1": "BHDL",
  105. "Sigle_2": "BIOS",
  106. "Name_1": "B Hardware Description Language",
  107. "Name_2": "Basic Input Output System"
  108. },
  109. {
  110. "Sigle_1": "BIPM",
  111. "Sigle_2": "BEST",
  112. "Name_1": "Brevet d'initiation au parachutisme militaire",
  113. "Name_2": "Board of European Students of Technology"
  114. },
  115. {
  116. "Sigle_1": "BHDL",
  117. "Sigle_2": "BIOS",
  118. "Name_1": "B Hardware Description Language",
  119. "Name_2": "Basic Input Output System"
  120. }
  121.  
  122. db.collections.aggregate([
  123. { "$facet": {
  124. "array1": [
  125. { "$group": {
  126. "_id": "$Sigle_1"
  127. }}
  128. ],
  129. "array2": [
  130. { "$group": {
  131. "_id": "$Sigle_2"
  132. }}
  133. ],
  134. "array3": [
  135. { "$group": {
  136. "_id": "$Name_1"
  137. }}
  138. ],
  139. "array4": [
  140. { "$group": {
  141. "_id": "$Name_2"
  142. }}
  143. ]
  144. }},
  145. { "$addFields": {
  146. "data": {
  147. "$concatArrays": ["$array1", "$array2"]
  148. },
  149. "data_1": {"$concatArrays": ["$array3", "$array4"]
  150. }
  151. }}
  152. ])
Add Comment
Please, Sign In to add comment