Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, that looks pretty good. Let's construct some of the queries.</p> <p>Assuming the collections are named users, events, venues:</p> <ul> <li><p><strong>Insert some dummy events</strong>:</p> <blockquote> <p>db.events.insert({tags:["awesome","fun","cool"]})</p> <p>db.events.insert({tags:["sweet","fun","rad"]})</p> </blockquote></li> <li><p><strong>Make an index</strong> (like a boss)</p> <blockquote> <p>db.events.ensureIndex({ tags: 1 })</p> </blockquote></li> <li><p><strong>Listing of distinct tags (this might be hard given current design)</strong>:</p> <p>Nope, not hard.</p> <blockquote> <p>db.events.distinct("tags")</p> </blockquote> <p>[ "awesome", "cool", "fun", "rad", "sweet" ]</p></li> <li><p><strong>Events in a given tag</strong> (you meant "with a given tag" right?)</p> <blockquote> <p>db.events.find({tags: "fun"})</p> </blockquote> <p>{ "_id" : ObjectId("4ecc08c62477605df6522c97"), "tags" : [ "awesome", "fun", "cool" ] }</p> <p>{ "_id" : ObjectId("4ecc08d92477605df6522c98"), "tags" : [ "sweet", "fun", "rad" ] }</p></li> <li><p><strong>Event information along with venue location</strong></p> <p>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.</p> <p><strong>OR</strong></p> <p>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.</p></li> <li><p><strong>All event and venue information for a particular event</strong></p> <p>See above</p></li> <li><p><strong>All events near me. Need to use a geo index on loc</strong></p> <p>Two queries again, same concept as above just reverse the order.</p> <p>Get the venues:</p> <blockquote> <p>db.venues.find( { loc : { $near : [lat,lon] } } )</p> </blockquote> <p>Get the events using the venue ids:</p> <blockquote> <p>db.events.find( { venue : { $in : [id1,id2,id3...] } } )</p> </blockquote></li> </ul> <p>Some of this stuff can be done automatically for you if you use an ODM.</p> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload