Reputation: 1951
Hi I am new to mongodb and still learning about the basics and structure (after coming from the sql world).
I am working on a test project with mongo where I am storing occurrences against an event.
So I have a collection of events (in this case 2000). Now I would like to store an occurrence next to each one (in this case 200,000 records per event).
SQL : Events (table) (1) <- Occurrence (table) (many)
In SQL I would have a 1 to many relationship to represent this. Whereby one event can have many occurrences.
In mongodb what would be the best way to display this data. Would it be best to have two collections one, events one occurrences. Or one collection with a massive document.
Thanks
Upvotes: 0
Views: 392
Reputation: 3760
Aside: a few thousand documents is definitely not a large amount of data :)
You could store the occurences inside the event document if a) you will never exceed the 16MB limit for a single document, so you don't have that many occurences per event, and b) you usually need all the occurences for a given event, so pulling the entire document from the database each time you need it does not waste a lot of bandwidth.
From your numbers, it sounds as if you have about 100 occurences per event. That's very little and I would definitely consider storing the occurences inside the events in this case (assuming that each occurence is little more than a time-stamp).
If you have more occurences (thousands of them), and/or if each occurence contains a substantial amount of data, and/or you rarely if ever want all the occurences for a given event, then I would put them into a separate collection.
Upvotes: 1