|
| 1 | +import Tabs from "@theme/Tabs"; |
| 2 | +import TabItem from "@theme/TabItem"; |
| 3 | + |
1 | 4 | # 👐 INSERT → insertOne() & DELETE → deleteOne()
|
2 | 5 |
|
3 | 6 | MongoDB provides two methods for inserting documents into a collection:
|
@@ -67,45 +70,94 @@ DELETE FROM reviews WHERE bookId = '0786222727';
|
67 | 70 |
|
68 | 71 | <details>
|
69 | 72 | <summary>Answer</summary>
|
70 |
| - <div> |
71 |
| - ```js |
72 |
| - db.reviews.insertMany([ |
73 |
| - { |
74 |
| - text: "Thrilling end.", |
75 |
| - rating: 4, |
76 |
| - name: "Mark", |
77 |
| - bookId: "0786222727", |
78 |
| - }, |
79 |
| - { |
80 |
| - text: "Must read!", |
81 |
| - rating: 5, |
82 |
| - name: "Raj", |
83 |
| - bookId: "0786222727", |
84 |
| - }, |
85 |
| - { |
86 |
| - text: "Very expensive", |
87 |
| - rating: 3, |
88 |
| - name: "Yun", |
89 |
| - bookId: "0786222727", |
90 |
| - }, |
91 |
| - { |
92 |
| - text: "Extremely satisfied with the storyline!", |
93 |
| - rating: 5, |
94 |
| - name: "Lisa", |
95 |
| - bookId: "0786222727", |
96 |
| - } |
97 |
| - ]); |
98 |
| - ``` |
99 |
| - </div> |
| 73 | + <Tabs groupId="challenges" defaultValue={"javascript"}> |
| 74 | + <TabItem value="javascript" label="JavaScript"> |
| 75 | + <div> |
| 76 | + ```js |
| 77 | + const reviews = db.collection("reviews"); |
| 78 | + await reviews.insertMany([ |
| 79 | + { |
| 80 | + text: "Thrilling end.", |
| 81 | + rating: 4, |
| 82 | + name: "Mark", |
| 83 | + bookId: "0786222727", |
| 84 | + }, |
| 85 | + { |
| 86 | + text: "Must read!", |
| 87 | + rating: 5, |
| 88 | + name: "Raj", |
| 89 | + bookId: "0786222727", |
| 90 | + }, |
| 91 | + { |
| 92 | + text: "Very expensive", |
| 93 | + rating: 3, |
| 94 | + name: "Yun", |
| 95 | + bookId: "0786222727", |
| 96 | + }, |
| 97 | + { |
| 98 | + text: "Extremely satisfied with the storyline!", |
| 99 | + rating: 5, |
| 100 | + name: "Lisa", |
| 101 | + bookId: "0786222727", |
| 102 | + } |
| 103 | + ]); |
| 104 | + ``` |
| 105 | + </div> |
| 106 | + </TabItem> |
| 107 | + <TabItem value="mongosh" label="mongosh"> |
| 108 | + <div> |
| 109 | + ```js |
| 110 | + db.reviews.insertMany([ |
| 111 | + { |
| 112 | + text: "Thrilling end.", |
| 113 | + rating: 4, |
| 114 | + name: "Mark", |
| 115 | + bookId: "0786222727", |
| 116 | + }, |
| 117 | + { |
| 118 | + text: "Must read!", |
| 119 | + rating: 5, |
| 120 | + name: "Raj", |
| 121 | + bookId: "0786222727", |
| 122 | + }, |
| 123 | + { |
| 124 | + text: "Very expensive", |
| 125 | + rating: 3, |
| 126 | + name: "Yun", |
| 127 | + bookId: "0786222727", |
| 128 | + }, |
| 129 | + { |
| 130 | + text: "Extremely satisfied with the storyline!", |
| 131 | + rating: 5, |
| 132 | + name: "Lisa", |
| 133 | + bookId: "0786222727", |
| 134 | + } |
| 135 | + ]); |
| 136 | + ``` |
| 137 | + </div> |
| 138 | + </TabItem> |
| 139 | + </Tabs> |
100 | 140 | </details>
|
101 | 141 |
|
102 | 142 | ### 👐 2. Delete all the reviews for `bookId` "0786222727" through a single command.
|
103 | 143 |
|
104 | 144 | <details>
|
105 | 145 | <summary>Answer</summary>
|
106 |
| - <div> |
107 |
| - ```js |
108 |
| - db.reviews.deleteMany({"bookId": "0786222727"}) |
109 |
| - ``` |
110 |
| - </div> |
| 146 | + <Tabs groupId="challenges" defaultValue={"javascript"}> |
| 147 | + <TabItem value="javascript" label="JavaScript"> |
| 148 | + <div> |
| 149 | + ```js |
| 150 | + const reviews = db.collection("reviews"); |
| 151 | + await reviews.deleteMany({"bookId": "0786222727"}) |
| 152 | + ``` |
| 153 | + </div> |
| 154 | + </TabItem> |
| 155 | + <TabItem value="mongosh" label="mongosh"> |
| 156 | + <div> |
| 157 | + ```js |
| 158 | + db.reviews.deleteMany({"bookId": "0786222727"}) |
| 159 | + ``` |
| 160 | + </div> |
| 161 | + </TabItem> |
| 162 | + </Tabs> |
111 | 163 | </details>
|
0 commit comments