PyMongo $inc having issues

后端 未结 2 1945
独厮守ぢ
独厮守ぢ 2021-01-13 02:46

When trying to use $inc I get a Syntax error stating that $set is wrong. My query is as follow:

mongo_db.campaign.update({\'_id\': str(campaign_id)}, { $inc:         


        
相关标签:
2条回答
  • 2021-01-13 03:03

    $inc isn't a valid Python identifier. You should pass it as a string, like everything else:

    mongo_db.campaign.update({'_id': str(campaign_id)}, {'$inc': {'item': 1}})
    

    The MongoDB docs you linked are the general MongoDB documentation, not PyMongo-specific; you can't copy/paste them literally and expect things to work.

    0 讨论(0)
  • 2021-01-13 03:15
    pymongo == 2.7 
    campaign_id = bson.ObjectId(campaign_id)
    mongo_db.campaign.update({'_id': campaign_id}, {'$inc': {'item': 1}})
    
    0 讨论(0)
提交回复
热议问题