Created
April 10, 2017 17:10
-
-
Save RWaltersMA/135ee6731ccd15d6c34051499de8698c to your computer and use it in GitHub Desktop.
Update showing effects of default upsert in mongodb PyMongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import MongoClient | |
#include pprint for readabillity of the | |
from pprint import pprint | |
#change the MongoClient connection string to your MongoDB database instance | |
client = MongoClient(port=27020) | |
db=client.business | |
ASingleReview = db.reviews.find_one({}) | |
print('A sample document:') | |
pprint(ASingleReview) | |
result = db.reviews.update_one({'_id' : ASingleReview.get('_id') }, {'$inc': {'likes': 1}}) | |
print('Number of documents modified : ' + str(result.modified_count)) | |
UpdatedDocument = db.reviews.find_one({'_id':ASingleReview.get('_id')}) | |
print('The updated document:') | |
pprint(UpdatedDocument) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment