【问题标题】:Update with pull in MongoDB 3.2.5 matching but not modifying document更新 MongoDB 3.2.5 匹配但不修改文档
【发布时间】:2016-08-18 13:16:02
【问题描述】:

我在 getJSON 请求上收到 500 错误,该请求映射到包含 MongoDB update$pullPython 2.7 函数。

sudo tail -f /var/log/apache2/error.log 出现的最后一个错误是:

[wsgi:error] [pid 1721:tid 140612911712000] 
[client 127.0.0.1:59078] 
KeyError: 'nModified', referer: http://localhost/control_room

处理这个特定键的 Python 逻辑是 update$pull

update_with_pull = collection.update({"user_email":user_email,"top_level.year":entry_year,"top_level.month":entry_month}, { "$pull": {dynamic_nested_key: {"timestamp":entry_timestamp}}})

这之后的条件是试图捕捉一个文档是否被修改过:

if update_with_pull['nModified'] == 1:
  #do stuff

我在 mongo shell 中测试了相同的操作并返回:

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })

所以它似乎与查询匹配,但没有进行任何修改。

为了进一步排除故障,上面$pull 部分中使用的entry_timestamp 值在数据库和函数中是一致的(即它们都是具有相同字符的字符串)。

一些想法:

  • 我刚刚将应用程序从2.6.11 移动到3.2.5 MongoDB 环境,这可能会导致问题,但是,如果是这样,我还不能确定是怎么回事。
  • $pull 的语法在 3.2.5 中发生了变化?
  • 集合存在权限问题,阻止修改?
  • 我在 virtualenv 中运行 pymongo 2.6.2 - 也许它与 MongoDB 3.2.5 存在一些不兼容?

【问题讨论】:

    标签: mongodb python-2.7 pymongo ubuntu-16.04


    【解决方案1】:

    解决方案

    升级到pymongo 3.2.2 会导致错误:

    ServerSelectionTimeoutError: No servers found yet
    

    https://stackoverflow.com/a/31194981/1063287

    不过,我升级到pymongo 2.8,重启了apache,问题似乎解决了。

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 2021-01-28
      • 1970-01-01
      • 2015-01-14
      • 2022-12-22
      • 2015-02-10
      • 1970-01-01
      • 2022-11-02
      • 2017-05-28
      相关资源
      最近更新 更多