Skip to content

Instantly share code, notes, and snippets.

@advorak
Last active April 2, 2020 23:23
Show Gist options
  • Select an option

  • Save advorak/c3a741824d009dc57ff32f50437a5af1 to your computer and use it in GitHub Desktop.

Select an option

Save advorak/c3a741824d009dc57ff32f50437a5af1 to your computer and use it in GitHub Desktop.

Revisions

  1. advorak revised this gist Apr 2, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion script.js
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@ db.episodes.updateMany({},[{$set: {created_at: "$data.date_gmt"}}])
    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")}
    // What am i doing wrong? :-) Thanks!
    db.episodes.updateMany({},[{$set: {created_at: {$dateFromString: {dateString:("$data.date_gmt")}}}}])
  2. advorak renamed this gist Apr 2, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. advorak created this gist Apr 2, 2020.
    7 changes: 7 additions & 0 deletions database.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // db.episodes.findOne({})
    {
    "_id" : ObjectId("5e8563a07aeda6f729a56e33"),
    "data" : {
    "date_gmt" : "2020-03-30T10:00:08"
    }
    }
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // 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")}
    // What am i doing wrong? :-) Thanks!