Migration - bulkWrite new connection issue Solution

If you are doing the bulkWrite lab and feel like you should be receiving something besides “0 documents found” or connection errors in your test, try this:

  1. I removed the host variable - and replace it in the .connect() method with my URI from the .env file.
  2. In the mflix variable (line 25) I put in “mflix” as a string into the client.db() function.

This worked for me. Not too sure why, though.

  const client = await MongoClient.connect(
  { useNewUrlParser: true },
const mflix = client.db("mflix")

Maybe somebody can bring clarity to this issue? Would be awesome :wink:


Well, it seems that our movie-last-updated-migration.js has no way reaching all those variables declared in the .env file. You can inspect it by adding console.log(process.env), you won’t find MFLIX_DB_URI or MFLIX_NS variables.

By adding this one line - require('dotenv').config({ path: '../../.env' }) at the top of movie-last-updated-migration.js, we will load all the variables from .env file into process.env of running movie-last-updated-migration.js

Since the .env file is located at the root level of our mflix-js project, we need to go all the way to the top from the current location of movie-last-updated-migration.js which sits in src/migrations , therefore - '../../.env'.