Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. {
  2. "_id" : ObjectId("58760d8caa30c585ef8d3beb"),
  3. "results" : [
  4. {
  5. "item" : "A",
  6. "score" : 5.0,
  7. "answers" : [
  8. {
  9. "q" : 1.0,
  10. "a" : 4.0
  11. },
  12. {
  13. "q" : 1.0,
  14. "a" : 5.0
  15. },
  16. {
  17. "q" : 2.0,
  18. "a" : 6.0
  19. }
  20. ]
  21. },
  22. {
  23. "item" : "B",
  24. "score" : 8.0,
  25. "answers" : [
  26. {
  27. "q" : 1.0,
  28. "a" : 7.0
  29. },
  30. {
  31. "q" : 1.0,
  32. "a" : 5.0
  33. },
  34. {
  35. "q" : 2.0,
  36. "a" : 9.0
  37. }
  38. ]
  39. }
  40. ]
  41. }
  42.  
  43. {
  44. "_id" : ObjectId("58760d8caa30c585ef8d3beb"),
  45. "results" : [
  46. {
  47. "item" : "A",
  48. "score" : 5.0,
  49. "answers" : [
  50. {
  51. "q" : 2.0,
  52. "a" : 6.0
  53. }
  54. ]
  55. },
  56. {
  57. "item" : "B",
  58. "score" : 8.0,
  59. "answers" : [
  60. {
  61. "q" : 2.0,
  62. "a" : 9.0
  63. }
  64. ]
  65. }
  66. ]
  67. }
  68.  
  69. db.getCollection('test').update({"results.answers.q":1},
  70. { $pull: {"results.$.answers": {q:1} } },
  71. { multi: true })
  72.  
  73. {
  74. "_id" : ObjectId("58760d8caa30c585ef8d3beb"),
  75. "results" : [
  76. {
  77. "item" : "A",
  78. "score" : 5.0,
  79. "answers" : [
  80. {
  81. "q" : 2.0,
  82. "a" : 6.0
  83. }
  84. ]
  85. },
  86. {
  87. "item" : "B",
  88. "score" : 8.0,
  89. "answers" : [
  90. {
  91. "q" : 1.0,
  92. "a" : 7.0
  93. },
  94. {
  95. "q" : 1.0,
  96. "a" : 5.0
  97. },
  98. {
  99. "q" : 2.0,
  100. "a" : 9.0
  101. }
  102. ]
  103. }
  104. ]
  105. }
  106.  
  107. db.getCollection('test').update({},{ $pull: {"results":{"answers": {$elemMatch:{q:1} }} }},{ multi: true });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement