Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting to Know MongoDB

Getting to Know MongoDB

This is the slide deck I use to introduce hackers to MongoDB when I have 2-5 minutes and I'm presenting at a hackathon. Hat tip to @samantharitter for the slide deck base, since all the wonderful design and most of the content is hers.

Amalia Hawkins

February 14, 2014
Tweet

More Decks by Amalia Hawkins

Other Decks in Programming

Transcript

  1. What can I do with it? \ZLYZ WYVK\J[ PUMVYTH[PVU ISVNWVZ[Z

    Z[VJR]HS\LZ YLJPWLZ ZJPLU[PMPJKH[H JVVYKPUH[LZ
  2. Creating Documents ‹4VUNV+)KVJ\TLU[Z Z\WWVY[YPJO MSL_PISLVIQLJ[ ZJOLTH UV[HISLZ > course =

    { title : ‘Operating Systems’, num : ‘318’, dept : ‘COS’, staff : { prof : ‘Kai Li’, TAs : [ ‘Yida Wang’, ‘Scott Erickson’, ‘Aaron Blankstein’ ] } };
  3. Simple Document Ops ‹*YLH[L ‹9LHK ‹<WKH[L ‹+LSL[L > db.courses.find({ prof

    : ‘Kevin Wayne’ }); > db.courses.insert( doc ); > db.courses.update({ dept : ‘COS’ }, { $set : { dist : ‘QR’ }}); > db.courses.remove();
  4. > tar –z xvf mongodb-osx-x86_64-2.4.8.tgz > cd mongodb-osx-i386-2.4.8/bin > mkdir

    –p /data/db > ./mongod 1. Download mongo ^^^TVUNVKIVYNKV^USVHKZ <UWHJRHUKY\U!
  5. 2. Get a driver ‹7`[OVU ‹9\I` ‹1H]H ‹7/7 HUKTHU`V[OLYZ >

    pip install pymongo > gem install mongo > pecl install mongo KV^USVHK'TVUNVKIVYNLJVZ`Z[LTKYP]LYZQH]H
  6. 3. Get coding! from pymongo import MongoClient def main(): #

    connect to the db connection = MongoClient() db = connection["hello_database"] collection = db["messages"] # create and save a document to the db doc = { "message" : "Hello, world!" } collection.save(doc) # get it back and print it out! result = collection.find_one() print result if __name__ == "__main__": main() FREE CODE!