Schema design questions for calendar/event

1,342 views
Skip to first unread message

Steve V

unread,
Mar 1, 2011, 11:08:33 AM3/1/11
to mongodb-user
First off, if there is a better place to ask schema design related
questions please let me know. I wasn't sure if this list was more for
the technical side of working with/configuring Mongo or not.

The short of it is that I'm looking to create a calendar/event system
where a users can subscribe to multiple calendars. I of course want to
be able to easily retrieve all events that apply to a given user for a
given set of criteria(usually date range).

I'm very familiar with relational database design, but very new to
document databases. In a relational design I would have calendars, and
events tables and that's it, because it's pretty much the only option.
In Mongo would I be better off embedding the events in the calendars
collection?

The events would also have additional data about them. Things like
report/review of the event, attendance report, or invite list. Would
those things be best placed as documents embedded in the event
document, or would it be better for them to live in their own
collection? Again, this would be done more or less one way in a rdbms,
but I'm looking to try and use the approach that best takes advantage
of Mongo. If in this case it ends up being the relational way, then
that's fine. I just don't want to try and plow along blindly trying to
make Mongo behave like an rdbms just because that's what I know.

Thanks,
Steve

Bernie Hackett

unread,
Mar 1, 2011, 11:35:33 AM3/1/11
to mongodb-user
This is a great place to ask schema design questions :)

How you design the "schema" in mongo really depends, as in other
systems, on how you want to query the data.

For example, if you want to have a strong life-cycle relationship
between an event and all the report data about it (attendance, invite
list, etc.) then
embedding this information in the event document makes a lot of sense.

One approach might be to have a "user" collection and an "events"
collection. The user documents could have an embedded array of event
IDs. Conversely, an event document could have an embedded array of
user IDs.

Be careful when deeply nesting documents as they can be difficult to
query on.

Steve V

unread,
Mar 2, 2011, 3:56:48 PM3/2/11
to mongodb-user
What you mentioned about the deeply nested documents is one of my main
concerns. I don't have enough knowledge yet to know what makes
querying go from sane, to nightmare. At what level does embedding
documents start to cause loss of sanity? Is it possible to reference
an embedded document directly from another collection very easily?

I hadn't considered the thought of having my user documents embed an
array of all applicable events. Not sure how I would handle recurring
events though. Given the open-ended timeframe of some of those I
wasn't planning on generating all events, but rather injecting the
recurring ones on the fly when the query was made(most likely in my
code and not the db call), and actually creating a new record only
when that event was actually viewed for the first time. I suppose a
similar pattern is still possible even with the arrays.

Thanks
Reply all
Reply to author
Forward
0 new messages