Ticket: Migration unit test issue

Hi everyone, kindly please help with the issue at hand. So I tried migrating script from the root folder and it would give me the following error:


I then solved that by running the node src/migrations/movie-last-updated-migration.js and managed to solve the problem:

But unfortunately, now when I try to run the unit test, I get the following error:

My code looks like this:

Can someone kindly please help me figure out what I am missing. Thanks

Hi @Tlotliso_Lehola, thanks for reaching out to us.
Please note that the movie-last-updated-migration.js file is note in the root directory of this project. You need to move to the /src/migrations folder to run this file, or else you can also mention the path in the command itself from the root directory.

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi,I did just that and it still gives me the same error. When I take a look at the format of the “lastupdated” field in the movies collection, it has changed to an ISODate format, which indicates the migration was successful. The problem arises when I run the unit test. What am I doing wrong or missing?

Hi @Tlotliso_Lehola,
Please make sure that you don’t have duplicate keys in a single object. For this instance, don’t use lastupdated twice in your query predicate, simply check if lastupdated is a string or not.

Also you might want to edit your update query to this:

  "$set": { "lastupdated": new Date(lastupdated) },

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

I made the suggested changes and it’s still giving me the same error.

This is what the new value of the “lastupdated” field looks like in compass:

Do not

I do not see any constructor, in Date - JavaScript | MDN, that uses a string as a parameter.

Also, if you look at Date.parse() - JavaScript | MDN you will see that you still do not get a Date but a number.

I am pretty sure that the code

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

as publish was adequate.

Hey, I finally managed to pass the unit test. Thanks for the help

If one of my post help you

kindly mark it as the solution so that others know to follow the same advice.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.