Ticket: Migration test doesn't work

I have written the code, fixed some issued with original code include the should-be-unchanged

const mflix = client.db(process.env.MFLIX_NS)

to seemed-to-work code

const mflix = client.db("sample_mflix")

When I ran node src/migrations/movie-last-updated-migration.js I received the result

Found 23539 documents to update
23539 documents updated

But when I run the test case the test just run

> server@1.0.0 test F:\Coding\Front-End\JavaScript\nodejs\mongodb\mongodb-for-nodejs
> jest --passWithNoTests "migration"

Determining test suites to run...Setup Mongo Connection

RUNS  test/migration.test.js

And then just hanging for more than 30 minutes. Even after I stop the server, close the command line and run again, still same result with the test. Also, when I go to status page, in the Migration section I got the message

Migration: It does not appear that you correctly converted the type

So what is the possible error of my code?

P.S: Even after I copy the solution with changing only the host to my cluster URI, I still get same error message

1 Like

Hi @Ann_90310,

This means you have already updated the documents successfully, but that does not tell about the type of lastupdated field.

One thing I would do is check the type of the field in the cluster and make sure its Date. If not, you may need to slightly modify your query to update again.


I try

lastupdated: new Date(lastupdated).toLocaleTimeString()`

Still not working
Then I realized that I can’t update the lastupdated field. Even when I change the lastupdated field to some random value like

lastupdated: 12

And run node src/migrations/movie-last-updated-migration.js , I still receive a same result

Found 0 documents to update
0 documents updated

Can you help me with this problem?

Try this:


Also, if you are unable to update:

  • check if connection string is updated in the js file

  • try after changing below line:

         const mflix = client.db("sample_mflix")


I have same problem. Can you solved this? npm test -t migration runs hanging and nothing output comes in.

Does the script ran successfully? Can you check if the changes have been reflected in the database sample_mflix ?


Yes. In atlas lastupdated is type of date. again, script runs successfully. Thanks you so much for your help. I figured out that at first run of migration script accidentally lastupdated field set to double rather than to date. then I re-run script to check type of lastupdated to ‘double’ and then in
updateOne{$set :{lastupdated: new Date(Date.parse(lastupdated))}} . and this works perfectly. In my case new Date() is work around for me.

1 Like

Perfect @Gaurang_89625. Thanks for the update.


1 Like

Thanks you so much to all Mentors of Mongodb. Today, I successfully passed M220 JavaScript course Completion Certification. Here is My Certificate… http://university.mongodb.com/course_completion/0bcca4ab-48ff-47b5-97aa-d2e851003c98
Journey is very wonderful more counting.

@kanikasingla and @Gaurang_89625

I still has the same issue. The issue where I can’t update the lastupdated is because the data type in predicate which used in find is incorrectly set to string instead of date

So I need to first set it to double to select all and update it. It can update now. But the test still doesn’t work as it hanging for too long. Again I have check that the type this time is correct (date as data type)

Do you have any suggestion of what might go wrong?

Edited: The test work now, and I can find the result in status page. After change the data type back to date it work just find. Just one issue that is after I made the change the test still fail. After three time retry to run the test it work.


1 Like