Ticket: Migration not converting type

Greetings, I am having difficulty completing this ticket. The tests do not pass and the validation on the localhost page says “Migration: It does not appear that you correctly converted the type”

When I check the data manually in Compass it shows that the line for lastupdated has been converted from String to Double, or to Date but not an ISODate. I have tried this several ways.

Please let me know if anyone as any thoughts, as this is the final exercise for this chapter, due in 2 days. I have read every other Topic I can find here and tried everything I have seen already. Many thanks!

        update: {
          $set: { lastupdated: Date.parse(lastupdated) },

The error I am getting is as follows:

 FAIL  test/migration.test.js
    ✕ migration (66ms)

  ● Migration › migration


    Received: null

      13 |     })
      14 |     console.log("movie: ", movie);
    > 15 |     expect(movie).not.toBeNull()
         |                       ^
      16 |   })
      17 | })
      18 |

      at toBeNull (test/migration.test.js:15:23)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

  console.log test/migration.test.js:14
    movie:  null

1 Like

@steevej-1495 @John_20352 Please take a look at this. With the help of @Kanika, I cleared the migration part, but Again this has put me on hold. Any help will be great. thanks.

Don’t worry guys. I have cleared it. Anyway, thanks for the help.

1 Like

First, please follow forum’s guideline and do not post code.

What is the URI of your server? Hint: it should be at the line that start with const host =.


I tried several versions of the conversion, and what finally did the trick was new Date(Date.parse(lastupdated))

It was also necessary for me to drop the collection, wait a few minutes for Mongo to update, then re-add the Sample Data. This was because my previous attempts using Date without ‘new’, or some variation of that, caused the lastupdated type to be Date but not an ISODate. Surely there is a way to convert directly between these two, but for now I was able to finish the task by reloading the Sample Data Set.

Many thanks and best of luck to all!

1 Like

Drop collection? I tried dropping, it gave atlas error from command line. How to drop it from atlas?

I have added the correct URI. Also Have added Date.parse() as was asked in instruction.


I manually deleted the collections on the Atlas website interface. Then it takes 5-10 minutes to fully clear enough space and you can then re-add the Sample Data. This is what worked for me after all.

Anything else please let me know.

It didn’t work for me until I wrapped new Date around Date.parse, and used a ‘fresh’ data set. Let us know your results.

no it didn’t work after it as well.

  • I added the changes that were asked to add in the movie-last-updated-migration.js.
  • Then I ran the node node movie-last-updated-migration.js , results below.
  • Than I ran npm test -t migration, result below.
  • My atlas, it clearly shows I deleted all the collections and then added sample data.
  • image

Please suggest something. What do I do? Any help would be great. Thanks.

Hi @Satyam95,

Please check your messages.


Thanks @Kanika, your hint worked like a charm!