【问题标题】:issue with the dateFromString operator for MongoDB using pymongo使用 pymongo 的 MongoDB 的 dateFromString 运算符问题
【发布时间】:2018-01-15 22:37:46
【问题描述】:

dateFromString 运算符有问题

我想使用dateFromString 运算符从字符串中解析日期。日期在某个集合的“已发布”字段中

我正在使用 Python 3.6.4,MongoDB shell 版本 v3.6.2,pymongo '3.6.0' 我收到以下错误消息:

pymongo.errors.OperationFailure:无法识别的表达式'$dateFromString'

有人可以帮忙吗?

这是我的代码

pipeline = [
    {
        '$limit' : 100
    },
    {
        '$project' : {
            'released': {
                '$cond': {
                    'if': {'$eq': ['$released', '']},
                    'then': '',
                    'else': {
                        '$dateFromString':{
                            'dateString': '$released'
                        }
                    }
                }
            },
        }
    },
    {
        '$out': 'movies_scratch'
    }
]

pprint.pprint(list(client.database.collection.aggregate(pipeline)))

谢谢

【问题讨论】:

  • 你的服务器版本是多少?运行 db.version() 确认 3.6 服务器版本
  • 啊,我在 MongoDB 服务器版本:3.4.10 我使用 Atlas 上的免费层版本,仅在 3.4 上可用 dateFromString 运算符仅在 3.6 及更高版本上可用我想我需要那就升级吧!感谢您的评论 Veeram

标签: mongodb python-3.x pymongo


【解决方案1】:

检查 mongoDB 数据库版本。如果您使用的是 Atlas 免费层,它仍然是 3.4.13 版本。您需要一个 mongoDB 3.6 版本才能使 $dateFromString 工作。

【讨论】:

  • 如果版本低于3.6怎么办?
猜你喜欢
  • 2021-12-31
  • 2022-01-14
  • 2018-08-29
  • 2022-01-23
  • 2013-12-31
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多