Text and Subfield Search not passing

Hey guys I completed this section but when I run the test it says that it still fails. I pretty sure I have the query correct but can’t seem to complete it.

    // TODO Ticket: Text and Subfield Search
    // Construct a query that will search for the chosen genre.
    const query = { genres: { $in: searchGenre } }
    const project = {}
    const sort = DEFAULT_SORT

    return { query, project, sort }
  }

this is the error I get when I run the test, It may have something to do with Babel. There was complications while installing but I thought I got through it. Please let me know and ty in advance.

Setup Mongo Connection
(node:28692) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL test/text-subfield.test.js
  Text and Subfield Search
    √ Can perform a text search (95ms)
    × Can perform a genre search with one genre (170ms)
    × Can perform a genre search with multiple genres (129ms)
    √ Can perform a cast search with one cast member (135ms)
    √ Can perform a cast search with multiple cast members (148ms)
    √ Can perform a search and return a non-default number of movies per page (143ms)

  ● Text and Subfield Search › Can perform a genre search with one genre

    expect(received).toEqual(expected) // deep equality

    Expected: 2539
    Received: 23530

      23 |     })
      24 |     expect(moviesList.length).toEqual(20)
    > 25 |     expect(totalNumMovies).toEqual(2539)
         |                            ^
      26 |     const firstMovie = moviesList[0]
      27 |     expect(firstMovie["title"]).toEqual("Gladiator")
      28 |   })

      at _callee3$ (test/text-subfield.test.js:25:28)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:293:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:118:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

  ● Text and Subfield Search › Can perform a genre search with multiple genres

    expect(received).toEqual(expected) // deep equality

    Expected: 3485
    Received: 23530

      34 |     })
      35 |     expect(moviesList.length).toEqual(20)
    > 36 |     expect(totalNumMovies).toEqual(3485)
         |                            ^
      37 |     const firstMovie = moviesList[0]
      38 |     expect(firstMovie["title"]).toEqual("2 Fast 2 Furious")
      39 |   })

      at _callee4$ (test/text-subfield.test.js:36:28)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:293:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:118:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 4 passed, 6 total
Snapshots:   0 total
Time:        2.326s
Ran all test suites matching /text-subfield/i.
Teardown Mongo Connection

Hi @Macus_Desir, that’s really strange.
The query, project, and sort looks good to me. However, there is a possibility that your data might got modified accidentally while you are doing the exercises. I would recommend you to reset the sample-dataset by following the steps mentioned in question 5 in this Frequently Asked Questions topic.
Also, try to debug the variables using console.log in order to investigate if there’s something wrong, which is not really apparent right now.

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

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

I am experiencing the same problem. I just finished reloading the sample data into my mflix db and still no luck. I have run console logs on all of the search parameters in the test and they all look like they’re producing identical queries.

    { genre: { '$in': [ 'Action' ] } }

      at Function.log [as genreSearchQuery] (src/dao/moviesDAO.js:125:13)

  console.log
    { genre: { '$in': [ 'Mystery', 'Thriller' ] } }

      at Function.log [as genreSearchQuery] (src/dao/moviesDAO.js:125:13)

  console.log
    { cast: { '$in': [ 'Elon Musk' ] } }

      at Function.log [as castSearchQuery] (src/dao/moviesDAO.js:100:13)

  console.log
    { cast: { '$in': [ 'Robert Redford', 'Julia Roberts' ] } }

      at Function.log [as castSearchQuery] (src/dao/moviesDAO.js:100:13)

  console.log
    { cast: { '$in': [ 'Robert Redford', 'Julia Roberts' ] } }

      at Function.log [as castSearchQuery] (src/dao/moviesDAO.js:100:13)

 FAIL  test/text-subfield.test.js
  Text and Subfield Search
    ✓ Can perform a text search (67ms)
    ✕ Can perform a genre search with one genre (204ms)
    ✕ Can perform a genre search with multiple genres (85ms)
    ✓ Can perform a cast search with one cast member (86ms)
    ✓ Can perform a cast search with multiple cast members (142ms)
    ✓ Can perform a search and return a non-default number of movies per page (118ms)

I am using the same query code as the original submission to produce this output.


    const searchGenre = Array.isArray(genre) ? genre : genre.split(", ")

    const query = { genre: { $in: searchGenre } }
    console.log(query) 
    const project = {title: 1, _id: 0}
    const sort = DEFAULT_SORT

    return { query, project, sort }
}

Any thoughts on what might be causing this behavior? When testing the page while running, the Genre search query produces a perpetual loading icon, while the other queries function as intended and quickly.

Thank you for any guidance on this!

Most likely because it is genres rather than

Thanks @steevej, but I guess the issue is something else since he was using the genres key before and was still getting the incorrect count.
Do you think there’s something else worth looking at, to resolve this issue?

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

I beg to differ. @Dan_Taylor posted code with genre as shown in the quoted message. Indeed @Macus_Desir was using genres but my reply was intended to Dan since I quoted him.

We do not have the full code from Marcus so we are not sure how he builds the variable searchGenre.

1 Like

The following seems to indicate that the paging code is not applying the filter correctly since you the received totalNumMovies is too big.

1 Like

You are correct! Wow - I can’t believe I was banging my head against the keyboard for a few hours because I missed an ‘s’.

Thanks!

1 Like