Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5fefbb7

Browse files
add update example
1 parent b34eef4 commit 5fefbb7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,36 @@ gte - Greater Than Equals
166166
ne - Not Equals
167167
```
168168

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+
169199
### Filters
170200

171201
Find all the documents with purchase price > 120:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /