a. g.
a. g.

Reputation: 21

issue with the dateFromString operator for MongoDB using pymongo

I have an issue with the dateFromString operator

I want to parse dates out of a string using the dateFromString operator. The dates are in the 'released' field in a certain collection

I am using Python 3.6.4, MongoDB shell version v3.6.2, pymongo '3.6.0' I am received the following error message:

pymongo.errors.OperationFailure: Unrecognized expression '$dateFromString'

Can someone help on this please?

This is my code

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)))

thx

Upvotes: 2

Views: 2735

Answers (1)

Krishna Tummalapalli
Krishna Tummalapalli

Reputation: 51

Check the mongoDB database version. If you are using the Atlas free tier it is still on 3.4.13 version. You will need a mongoDB 3.6 version for $dateFromString to work.

Upvotes: 5

Related Questions