1

I have Ubuntu 20.04 server with MongoDB 5.0 installed and running by official tutorial. I encountered problem with some timezones, for example Etc/UTC timezone. I get the error "unrecognized time zone identifier":

> db.data.insert({ dt: new ISODate() })
WriteResult({ "nInserted" : 1 })
> db.data.aggregate([
...     {
...         "$project": {
...             "dtTimezone": {
...                 "$dateToString": {
...                     "date": "$dt",
...                     "timezone": "Etc/UTC"
...                 }
...             }
...         }
...     }
... ])
uncaught exception: Error: command failed: {
    "ok" : 0,
    "errmsg" : "PlanExecutor error during aggregation :: caused by :: unrecognized time zone identifier: \"Etc/UTC\"",
    "code" : 40485,
    "codeName" : "Location40485"
} with original command request: {
    "aggregate" : "data",
    "pipeline" : [
        {
            "$project" : {
                "dtTimezone" : {
                    "$dateToString" : {
                        "date" : "$dt",
                        "timezone" : "Etc/UTC"
                    }
                }
            }
        }
    ],
    "cursor" : {
        
    },
    "lsid" : {
        "id" : UUID("24a0ca58-6d03-4827-b59c-4bd82ddf9976")
    }
} on connection: connection to 127.0.0.1:27017 : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:719:17
assert.commandWorked@src/mongo/shell/assert.js:811:16
DB.prototype._runAggregate@src/mongo/shell/db.js:276:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1058:12
@(shell):1:1

At the same time, when using Europe/London, everything works:

> db.data.aggregate([
...     {
...         "$project": {
...             "dtTimezone": {
...                 "$dateToString": {
...                     "date": "$dt",
...                     "timezone": "Europe/London"
...                 }
...             }
...         }
...     }
... ])
{ "_id" : ObjectId("611832f076340952c425ce80"), "dtTimezone" : "2021-08-14T22:17:36.349Z" }

I found similar problem, but the solution was to comment "processManagement.timeZoneInfo" option and use internal timezones database. I've also tried copying timezones database from the MongoDB documentation, but it doesn't make any difference:

curl -O https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip
unzip timezonedb-latest.zip
rsync -a --delete timezonedb-2021a/ /usr/share/zoneinfo/
systemctl restart mongod

What could be the problem? Why the system database doesn't fit or work together with MongoDB?

5
  • I don't think "Etc/UTC" is a valid time zone name (in the Olsen timezone database) Use "UTC" or just skip this parameter because UTC is the default. Commented Aug 15, 2021 at 9:21
  • @WernfriedDomscheit This is correct timezone according to this list. Query with Etc/UTC timezone are executed when using internal timezones database by commenting "processManagement.timeZoneInfo option". I can ignore Etc/UTC because it is the same as UTC, but my data has Etc/GMT+12 timezone that I cannot ignore. Commented Aug 15, 2021 at 11:30
  • What about using +12:00 instead of Etc/GMT+12? It's the same, just a different format. Commented Aug 15, 2021 at 11:37
  • 1
    @WernfriedDomscheit Timezone Etc/GMT+12 equals UTC-12. This data comes from external source, I have to process it and I want to use MongoDB features to do it. I need a common solution. Commented Aug 16, 2021 at 17:47
  • Is it an option to use an external library, e.g. moment.js? Commented Aug 16, 2021 at 21:03

1 Answer 1

1

It was a bug in MongoDB, fixed in 5.0.4: https://jira.mongodb.org/browse/SERVER-59701

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.