My first encounter with MongoDB has left me puzzled about creating references between documents that are already in the database. Unlike SQL, I am unsure how to establish relationships between collections.
I have two collections: Films and Actors. The Films collection contains information about different movies, like titles, unique URLs, descriptions, etc. Here is an example document from the Films collection:
{
"_id": {
"$oid": "6272aa886441c51b18de7b23"
},
"type": "Film",
"title": "Les 2 papas et la maman",
"genres": "Comedia",
"description": "Jérôme and Delphine want a child but Jerome is sterile. They then ask the best friend of Jerome, Salim, to be the donor for artificial insemination of the mother...",
"platform": "Netflix"
"film_url": "exampleurl.com"
}
The second collection is called "Actors", each document containing details about a specific actor, the movie they star in (with title and URL), and the character they play. A sample document from the Actors collection could look like this:
{
"_id": {
"$oid": "6272ac5b6441c51b18de9ee4"
},
"name": "Sophie Rundle",
"film_title": "Peaky Blinders",
"film_url": "exampleurl.com",
"character": "Ada Shelby",
"num_episodes": "36"
}
I aim to create a OneToMany reference linking Films and Actors. This means a film can have multiple actors and each actor can represent a character in a film. To achieve this, I plan on adding an array within each Film document, containing the IDs of participating actors. Although I have unique "film_url" fields in both collections and data stored in CSV files, manually reading and iterating through over 10,000 lines in each file doesn't seem very efficient.
Is there a more straightforward and efficient method to establish these references in MongoDB?