Pymongo implements the method to control the Number Fields in mongodb for addition.
This article describes how to control the addition of numeric fields in mongodb using pymongo. Share it with you for your reference. The specific analysis is as follows:
This is very practical. For example, if we need to make access statistics for the article, we can set a numeric field: hit, and then add 1 to the field after each click.
Import pymongo # import the pymongo module conn = pymongo. connection () # connect to the local mongodb database db = conn. database # database is the database Name collection = db. article # article is the collection name, which is equivalent to the Table Name collection in mysql. update ({'_ id': ObjectId (id),' $ inc': {'hit': 1}) # Add 1 to the hit Field
I hope this article will help you with Python programming.