• Pros and Cons of using a LAMP stack (emphasis on M) • Needs of web applicaKons – internal and external • Using MongoDB for pre-‐exisKng RDBMS (relaKonal database management system) applicaKon • MigraKng exisKng mysql schema into MongoDB • Convincing stakeholders to use a nosql db
a pain • Slow queries are common from Hibernate abstracKon • Slow queries can lock mulKple tables • SeYng up mulK-‐master failover cluster requires a lot of work • Need DBAs
up the enKre applicaKon. Or rewrite it from scratch. Does it even make sense to? • Find places to uKlize MongoDB to supplement or replace exisKng pieces where it makes sense. • These new features will help demonstrate viability and uKlity of MongoDB for stakeholders
method call in a Hibernate object. • Be sure to put an index on the primary id of the RDBMS reference row. (or mulK column index) • db.customField.ensureIndex({contentId:1,siteId:1,contentTypeId:1});
• UKlize GridFS to store serializable objects for snapshots, caching purposes. • Note: GridFS Java API not same as MongoDB Java API (but similar enough to figure out) • GridFS files can not be replaced old files must be deleted first before storing a new file.
ByteArrayOutputStream bStream = null; ObjectOutputStream oStream = null; GridFSInputFile inputFile = null; bStream = new ByteArrayOutputStream(); oStream = new ObjectOutputStream(bStream); //Have the objectoutputstream get the serializable object oStream.writeObject(revision.getContent()); inputFile = myFS.createFile(bStream.toByteArray()); //set meta data for GridFS object so it's easy to query on inputFile.put("contentId", revision.getContentId()); inputFile.put("contentTypeId", revision.getContentTypeId()); inputFile.put("siteId", revision.getSiteId()); inputFile.put("_id", revision.getId()); inputFile.save();
it makes sense to move a set of normalized tables into MongoDB. • Do the tables o=en end up in the same de-‐normalized object format (memcache) ? • Consider high read elements – user analyKcs, comments, social inputs.
de-‐normalized object as the starKng point • Does it make sense to equate each row to a document? • Avoid puYng highly updated and queried values in a deeply embedded field
that can be printed out as a JSON format that meets the new MongoDB schema and store it. • Simple and dirty soluKon. Use a GSON (or equivalent) JSON wrangler the converts Java objects to JSON.
MySQL / Oracle with supplemental features using MongoDB. (object snapshots / custom fields) -‐ Must be consistent • High read external components and webservices uses MySQL(with memcache) and MongoDB. -‐ Must be horizontally scalable