0

I have two collections. Let's say, I want to search all the names of people in Parent table where place in child table = "Amsterdam". In SQL this would be something like this,

SELECT p.name FROM ParentTable p INNER JOIN ChildTable c ON p._id = c.parent_id WHERE place = "Amsterdam";

Following is the database schema, Database Schema

Now, I am new to the world of NoSQL databases. How should I structure my MongoDB database to achieve something similar to the above? Should I nest the collections or is there a way to reference the collections like the Foreign Key in SQL.

AashishKSahu
  • 335
  • 2
  • 15
  • 1
    Does this answer your question? [How do I perform the SQL Join equivalent in MongoDB?](https://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb) – Sunil K Samanta Oct 10 '20 at 06:59

1 Answers1

1

There is nothing like foreign key. And you can't join multiple collections either. What you can do is use $lookup pipeline operator in aggregation. Already answered here => How do I perform the SQL Join equivalent in MongoDB?

Sunil K Samanta
  • 161
  • 1
  • 8