I have a collection "films" with the following fields :
_id Actors Category Description Length Rating Rental Duration Replacement Cost Special Features Title
Actors is an array with three fields
"First name" "Last name" "actorId"
Sample documents from films
{"_id":1,
"Actors":[{"Last name":"GUINESS",
"actorId":1,
"First name":"PENELOPE"},
{"First name":"CHRISTIAN",
"Last name":"GABLE",
"actorId":10},
{"First name":"LUCILLE",
"Last name":"TRACY",
"actorId":20},
{"actorId":30,
"First name":"SANDRA",
"Last name":"PECK"},
{"First name":"JOHNNY",
"Last name":"CAGE",
"actorId":40},
{"First name":"MENA",
"Last name":"TEMPLE",
"actorId":53},
{"First name":"WARREN",
"Last name":"NOLTE",
"actorId":108},
{"First name":"OPRAH",
"Last name":"KILMER",
"actorId":162},
{"First name":"ROCK",
"Last name":"DUKAKIS",
"actorId":188},
{"First name":"MARY",
"Last name":"KEITEL",
"actorId":198}],
"Category":"Documentary",
"Description":"A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies",
"Length":"86",
"Rating":"PG",
"Rental Duration":"6",
"Replacement Cost":"20.99",
"Special Features":"Deleted Scenes,
Behind the Scenes",
"Title":"ACADEMY DINOSAUR"}
{"_id":2,
"Actors":[{"First name":"BOB",
"Last name":"FAWCETT",
"actorId":19},
{"First name":"MINNIE",
"Last name":"ZELLWEGER",
"actorId":85},
{"First name":"SEAN",
"Last name":"GUINESS",
"actorId":90},
{"First name":"CHRIS",
"Last name":"DEPP",
"actorId":160}],
"Category":"Horror",
"Description":"A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China",
"Length":"48",
"Rating":"G",
"Rental Duration":"3",
"Replacement Cost":"12.99",
"Special Features":"Trailers,
Deleted Scenes",
"Title":"ACE GOLDFINGER"}
I want 1/ to create a text index the actors fields along with "Category" and "Description" 2/ to search for an actor first name or last name and find it.
I used this
db.films.createIndex(
{
Category: "text",
Description: "text",
"Actors.'First name'": "text",
"Actors.'Last name'": "text"
},
{
weights: {
Category: 5,
Description: 5,
"Actors.'First name'":20,
"Actors.'Last name'":20
},
name: "ix_text"
}
)
When I query the collection
db.films.find( { $text: { $search: "SANDRA" } } ).pretty()
I get no result, although "SANDRA" exists in the Actors array
What is wrong? My index, my query, or both ?