Chapter 1: Driver Setup ,Ticket 3

public List getMoviesByCast(String sortKey, int limit, int skip, String… cast) {
Bson castFilter = Filters.in(“сasts”,cast);
Bson sort = Sorts.descending(sortKey);
//TODO> Ticket: Subfield Text Search - implement the expected cast
// filter and sort
List movies = new ArrayList<>();
moviesCollection
.find(castFilter)
.sort(sort)
.limit(limit)
.skip(skip)
.iterator()
.forEachRemaining(movies::add);
return movies; }

test Search by cast failed.
Help me understand what I’m doing wrong

Hi @Dmitriy_52646,

Do not forget to check the correct field names for the documents.
Here’s an example:

db.movies.findOne()
{
  "_id": ObjectId("573a1390f29313caabcd41b1"),
  "title": "The Bewitched Inn",
  "year": 1897,
  "runtime": 2,
  "cast": [
    "Georges Mèliès"
  ],
  "plot": "A weary traveler stops at an inn along the way to get a good night's sleep, but his rest is interrupted by odd happenings when he gets to his room--beds vanishing and re-appearing, candles ...",
  "fullplot": "A weary traveler stops at an inn along the way to get a good night's sleep, but his rest is interrupted by odd happenings when he gets to his room--beds vanishing and re-appearing, candles exploding, pants flying through the air and his shoes walking away by themselves.",
  "lastupdated": ISODate("2015-08-29T04:17:59.703Z"),
  "type": "movie",
  "directors": [
    "Georges Mèliès"
  ],
  "writers": [
    "Georges Mèliès"
  ],
  "imdb": {
    "rating": 6.5,
    "votes": 329,
    "id": 138
  },
  "countries": [
    "France"
  ],
  "genres": [
    "Short",
    "Comedy"
  ],
  "num_mflix_comments": 2
}

N.

so,my problem in Filters?

Hi @Dmitriy_52646,

The code you are providing translates into the following find command in the mongo shell:

// some set of cast members in casts array
var casts = []
db.movies.find({"casts": casts})

Check your filter expression.

1 Like

Now i dont cant use validation code? ((