Ticket: text-subfield

Hello everyone,

I 've used the query like the one for cast ,changing the searchGenre with array of genres expected in test but didn’t work.
I’ve also made the queries for one genre and result was null and for many nothing was returned in Compass as below.


I don’t know what I did wrong .
Many thanks for any ideas.

There is no field named genre in this name space.

1 Like

Hello ,
Thank You a lot for being so kind ,I was focused on function argument and took the singular.Like in games You gave me another life and I was happy to see at least one test passing.I can’t pass both.The query is a constant and if I pass to $in operator the array with the two genres, the test for one genre fail and vice versa.I don’t know how query the both predicates in same constant.Do I need another operator?
I have no IT background and even I read a lot, it is never enough but have no practice and practising without guidance it’s overwhelming.When I saw what’s next at pagination I thought that text-subfield will be my last ticket, in the best case.
All the best :four_leaf_clover:and a happy day.

It is supposed to work in both cases. Provide screenshot of what you are doing.

Hello again,
When I pass multiple genre ,I don’t pass the one genre test.
const query = {genres: {$in: ["Mystery","Thriller"]}}


and vice-versa ,when pass one genre ,I fail the many genre test,
and if I try to pass the all expected genres :for one and many genres in the same array I fail the both tests.
const query = {genres: {$in: [“Action”]}}
● Text and Subfield Search › Can perform a genre search with multiple genres
Test Suites: 1 failed, 1 total
Tests: 1 failed, 5 passed, 6 total
const query = {genres: {$in: [“Action”,“Mystery”,“Thriller”]}}
Test Suites: 1 failed, 1 totalled I’,
Tests: 2 failed, 4 passed, 6 total
Snapshots: 0 total
I’m confused and haven’t any better solution.
Best regards and I’m so grateful .

I am not too sure, but I suspect that you are using hard-coded values in your code rather than using the array received as parameter.

Your code should not look like:

const query = {genres: {$in: [“Mystery”,“Thriller”]}}

or

const query = {genres: {$in: [“Action”]}}

or

const query = {genres: {$in: [“Action”,“Mystery”,“Thriller”]}}

It should look like:

const query = {genres: {$in: name_of_the_parameter }} ;

The parameter holds the value needed by the tests.

1 Like

You’re such an amazing person; thanks.First I tried to use indeed the given param but test failed and then after looking into the test ,because my lack of experience I thought that I need to take the values expected in test.Now I’ve downloaded from lesson handouts the mflix-js folder and all test are good thanks to You.Be healthy! :100:


Text and Subfield Search: Did not receive the proper response when searching by genre

:smiley:I read I’m not the first with this case.

I had the same error a bit ago and just figured it out. I had the wrong variable in my query so it was not always passing in an array and the genre query needs an array.

2 Likes

@Brittany_Javalera
Thanks a lot for Your kind response.It’s interesting that I’ve passed all tests with the second variable too, but none of them gives me access to the ticket code.

I tried to put the variable inside but so tests failed and as a string too.I don’t know what else to do.
Wish You being well and have a nice day.

You should only do that when the variable is not already an array. See Array.isArray() - JavaScript | MDN to determine if it is already an array or not.

This course is indented to JavaScript developers, so I would recommend that you spend some time on Introduction - JavaScript | MDN before going forward with this course.

1 Like

@steevej-1495 Thanks .
That means that it should work by query with the variable which is already an array and still doesn’t.-in the way that tests passed but not return code for passing the ticket.
Have a nice time.

No really. If the variable is already an array and you put in between brackets you end up with and array of array. You can experience that with the mongo shell with:

mongo shell> var this_is_a_string = "steevej" ;
mongo shell> var this_is_an_array = [ "monica" ] ;
mongo shell> var this_is_another_array = [ this_is_a_string ] ;
mongo shell> var this_is_an_array_of_array = [ this_is_an_array ] ;
mongo shell> this_is_a_string
steevej
mongo shell> this_is_an_array
[ "monica" ]
mongo shell> this_is_another_array
[ "steevej" ]
mongo shell> this_is_an_array_of_array
[ [ "monica" ] ] 

So if you use the brackets when it is an array, then it fails because you have an array of arrays, rather than an array of strings. And if you do not put the variable inside brackets when it is a string, then if fails because you do not have an array of strings.

1 Like