Chris Muench
Chris Muench

Reputation: 18318

Mongo DB Design For Events Calendar

We have an events calendar and here is what I am thinking for our basic mongo schema:

users

events

venues

Queries that will be done are:

Any feedback/ideas on if we should be nesting venues inside events or use mysql instead?

Upvotes: 3

Views: 4954

Answers (1)

Tyler Brock
Tyler Brock

Reputation: 30136

Ok, that looks pretty good. Let's construct some of the queries.

Assuming the collections are named users, events, venues:

  • Insert some dummy events:

    db.events.insert({tags:["awesome","fun","cool"]})

    db.events.insert({tags:["sweet","fun","rad"]})

  • Make an index (like a boss)

    db.events.ensureIndex({ tags: 1 })

  • Listing of distinct tags (this might be hard given current design):

    Nope, not hard.

    db.events.distinct("tags")

    [ "awesome", "cool", "fun", "rad", "sweet" ]

  • Events in a given tag (you meant "with a given tag" right?)

    db.events.find({tags: "fun"})

    { "_id" : ObjectId("4ecc08c62477605df6522c97"), "tags" : [ "awesome", "fun", "cool" ] }

    { "_id" : ObjectId("4ecc08d92477605df6522c98"), "tags" : [ "sweet", "fun", "rad" ] }

  • Event information along with venue location

    You can do this a couple different ways. One way would be to query for the event and subsequently query for the venue. With both documents, join (combine) the data you want manually.

    OR

    You can denormalize a bit and store cached venue names + locations (but not venue details like hours of operation, max occupancy, website, phone number, etc..) for a speed boost (1 query instead of 2) That method comes with the standard denormalization caveat of not being able to update your data in one place.

  • All event and venue information for a particular event

    See above

  • All events near me. Need to use a geo index on loc

    Two queries again, same concept as above just reverse the order.

    Get the venues:

    db.venues.find( { loc : { $near : [lat,lon] } } )

    Get the events using the venue ids:

    db.events.find( { venue : { $in : [id1,id2,id3...] } } )

Some of this stuff can be done automatically for you if you use an ODM.

Good luck!

Upvotes: 4

Related Questions