Last active
April 2, 2020 23:23
-
-
Save advorak/c3a741824d009dc57ff32f50437a5af1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// db.episodes.findOne({}) | |
{ | |
"_id" : ObjectId("5e8563a07aeda6f729a56e33"), | |
"data" : { | |
"date_gmt" : "2020-03-30T10:00:08" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I want to take the field data.date_gmt and convert it from a text object to a new Date() object. | |
// This one sets {created_at: "2020-03-30T10:00:08Z"} | |
db.episodes.updateMany({},[{$set: {created_at: "$data.date_gmt"}}]) | |
// This one sets {created_at: ISODate("1970-01-01T00:00:00Z")} | |
db.episodes.updateMany({},[{$set: {created_at: (new Date("$data.date_gmt" + "Z"))}}]) | |
// My goal is to set to: {created_at: ISODate("2020-03-30T10:00:08Z")} | |
db.episodes.updateMany({},[{$set: {created_at: {$dateFromString: {dateString:("$data.date_gmt")}}}}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment