> use test
switched to db test
> version()
4.2.8
> db.test.find({})
{{
{ "_id" : ObjectId("5efbaba4250838017f12c045"), "dateString" : "2006-01-02T15:04:05.123456789Z" }
}}
> db.test.aggregate([\{$project: {date: {$dateFromString: {dateString: '$dateString'}}}}])
2020-06-30T14:22:04.013-0700 E QUERY [js] uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "Error parsing date string '2006-01-02T15:04:05.123456789Z'; 0: passing a time zone identifier as part of the string is not allowed '2'",
"code" : 241,
"codeName" : "ConversionFailure"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:583:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12
@(shell):1:1
> db.test.aggregate([{$project: {date: {$dateFromString: {dateString: {$substrBytes: ['$dateString', 0, 28]}}}])}}
{{
{ "_id" : ObjectId("5efbaba4250838017f12c045"), "date" : ISODate("2006-01-02T15:04:05.123Z") }
}}
> db.test.aggregate([{$project: {date: {$dateFromString: {dateString: {$substrBytes: ['$dateString', 0, 29]}}}])}}
2020-06-30T14:21:22.393-0700 E QUERY [js] uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "Error parsing date string '2006-01-02T15:04:05.123456789'; 0: passing a time zone identifier as part of the string is not allowed '2'",
"code" : 241,
"codeName" : "ConversionFailure"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:583:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12
@(shell):1:1
> ISODate('2006-01-02T15:04:05.123456789Z')
ISODate("2006-01-02T15:04:05.123Z")
> Date('2006-01-02T15:04:05.123456789Z')
Tue Jun 30 2020 14:23:41 GMT-0700 (PDT)
> db.test.updateOne({_id: ObjectId('5efbaba4250838017f12c045')}, {$set: {'dateString': '2006-01-02T15:04:05.12345678Z')}}
{{
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
}}
> db.test.aggregate([\{$project: {date: {$dateFromString: {dateString: '$dateString'}}}}])
{{
{ "_id" : ObjectId("5efbaba4250838017f12c045"), "date" : ISODate("2006-01-02T15:04:05.123Z") }
}}
> db.test.updateOne({_id: ObjectId('5efbaba4250838017f12c045')}, {$set: {'dateString': '2006-01-02T15:04:05.123456789Z')}}
{{
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
}}
> db.test.aggregate([\{$project: {date: {$dateFromString: {dateString: '$dateString'}}}}])
2020-06-30T14:37:05.058-0700 E QUERY [js] uncaught exception: Error: command failed: {
{{ "ok" : 0,}}
{{ "errmsg" : "Error parsing date string '2006-01-02T15:04:05.123456789Z'; 0: passing a time zone identifier as part of the string is not allowed '2'",}}
{{ "code" : 241,}}
{{ "codeName" : "ConversionFailure"}}
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:583:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12
@(shell):1:1
>