@@ -166,6 +166,36 @@ gte - Greater Than Equals
166
166
ne - Not Equals
167
167
```
168
168
169
+ ## Updates
170
+
171
+ Let's say we want to change a transactions payment method from credit card to account:
172
+
173
+ ```
174
+ >>> transactions.find_one({'account_id':'sns_03821023'})
175
+ {u'account_id': u'sns_03821023', u'store_name': u'sportsmans', u'purchase_method': u'credit card', u'branch_name': u'tygervalley', u'products_purchased': [u'cricket bat', u'cricket ball', u'sports hat'], u'_id': ObjectId('5cb18881df585e003c976d5d'), u'total_costs': 109.2}```
176
+ ```
177
+
178
+ Update the purchase_method to account:
179
+
180
+ ```
181
+ >>> transactions.update( {'account_id': 'sns_03821023'}, {'$set': {'purchase_method': 'account'}})
182
+ {'updatedExisting': True, u'nModified': 1, u'ok': 1.0, u'n': 1}
183
+ ```
184
+
185
+ Verify:
186
+
187
+ ```
188
+ >>> transactions.find_one({'account_id':'sns_03821023'})
189
+ {u'account_id': u'sns_03821023', u'store_name': u'sportsmans', u'purchase_method': u'account', u'branch_name': u'tygervalley', u'products_purchased': [u'cricket bat', u'cricket ball', u'sports hat'], u'_id': ObjectId('5cb18881df585e003c976d5d'), u'total_costs': 109.2}
190
+ ```
191
+
192
+ This examples is only intended for a single document and mongodb only updates one document at a time. To update more than one at a time:
193
+
194
+ ```
195
+ transactions.update( {'k': 'v'}, {'$set': {'k': 'new_v'}},{multi:true})
196
+ ```
197
+
198
+
169
199
### Filters
170
200
171
201
Find all the documents with purchase price > 120:
0 commit comments