Counter with Python and MongoDB
Part of the counter examples using Python and MongoDB.
examples/python/count_with_mongo.py
import sys from pymongo import MongoClient, ReturnDocument if len(sys.argv) != 2: exit("Usage: {} name".format(sys.argv[0])) name = sys.argv[1] connector = "mongodb://localhost" client = MongoClient(connector) db = client.mydb res = db.counter.find_one_and_update( { '_id': name }, { '$inc' : {'value' : 1 } }, upsert = True, return_document=ReturnDocument.AFTER) print(res)
Published on 2019-05-08
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post