Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
optimize Drupal using      mongoDB
agendalet’s get startedwhat is problem that we face (or what we need/want)sql - relational databasesshift of technologies ...
about mename: Vladimir Ilicemployed at: OWFGemail: v_ilic@hotmail.comt witter: burgerboydaddy
Who should be here instead of me
Who should be here instead of me
Who should be here instead of me
what is problem that we faceor what we want to achievewith Drupal based solutions
what is problem that we faceor what we want to achievewith Drupal based solutions speed
what is problem that we faceor what we want to achievewith Drupal based solutions speed        scale
what is problem that we faceor what we want to achievewith Drupal based solutions speed        scale                simpli...
how we can do that?or how to speedup Drupalserver side   install Varnish for caching pages for   anonymous users.   instal...
how to speedup drupal -       code sideuse Pressflow, it allows Varnish to serve cached page foranonymous users.clean Drup...
how to speedup drupal -    database sideDrupal sites live or die by their database.make sure the tables are properlyindexe...
speed -shift of technologiesfrom Pentium 100MHz, 16MB RAM,200 MB HDD tomy cell phone: dual core 1GHz, 1GB RAM,32GB storage...
our database technology
our database technology
our database       technology1974 - Therelationaldatabase is created
sql - relational dbs
sql - relational dbs1979
sql - relational dbs1979   1982-1996
sql - relational dbs1979   1982-1996   1995
simplicity?relational database model for eCommerce app
simplicity?relational database model for eCommerce app
simplicity?* joins* joins* joins   relational database model for eCommerce app
real life example              sell groceriesProduct {                          General Productid:                       a...
real life example -   but we also sell booksProduct {id:                                    General ProductUPC:           ...
real life example -        ops, we want moreProduct {                              General Productid:                     ...
Now we’re screwed
Now we’re screwed
shift of technologies -      db solutionsfrom well-established relational databases to NoSQLtechnologies.NoSQL was first i...
shift is happening now few years ago (and still now) MySQL was the undisputed king of the open-source database hill. It is...
shift is happening now
shift is happening now
shift is happening now451 Research notes:"NoSQL database technologies are largely being adopted fornew projects that requi...
shift is happening now451 Research notes:"NoSQL database technologies are largely being adopted fornew projects that requi...
the NoSQL ecosystem
what is Not Only SQL?
what is Not Only SQL?•Non-Relational   •Schema-Free•Distributed      •Replication Support•Open-Source      •Simple API•Hor...
mongoDB  agile and scalableDB designed for todayMongoDB (from "humongous") is ascalable, high-performance, open sourceNoSQ...
what is mongo          Application      Document                           Oriented    High                           { au...
other features of MongoDB  Document-based queries       Flexible document queries expressed in JSON/Javascript.  Map Reduc...
what is mongoDocument oriented storage  JSON-style documents with dynamic schemas offer simplicity and power.Full index su...
mongoDB philosophyKeep functionality when we can (key/value stores are great, but we needmore)Non-relational (no joins) ma...
6 mongoDB conceptsMongoDB has the same concept of a d atabase withwhich you are likely already familiar (or a schemafor yo...
6 mongoDB conceptsA document is made up of one or more fields, which youcan probably guess are a lot like c olumns.Indexes...
our eCommerce problem again
our eCommerce problem again           { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),           ‘customer_id’: ObjectId("4...
our eCommerce problem again                                { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),                ...
our eCommerce problem again                                { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),                ...
our eCommerce problem again                                { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),                ...
our eCommerce problem again                                { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),                ...
our eCommerce problem again                                 { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),               ...
our eCommerce problem again                                 { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),               ...
and some basic operationsQueryingAll the following queries will find the document.                                        ...
how to install mongoyou can have mongo on virtually any platform(Windows, OS X, Linux, Solaris, FreeBSD)mongo on Ubuntu in...
basic mongo commands db.help() -- also db.help (no parentheses) show dbs -- show databases use -- for selecting database d...
basic mongo commands  use learn         <--- switched to db learn  > db.getCollectionNames()  [ ]  > db.starwars.insert({n...
basic mongo commands  > db.starwars.find()  { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"),  "name" : "C-3PO", "gender" : ...
Drupal & mongoIn Drupal 7 if you use field API you want your fields insidemongodb. If you store them inside sql you cannot...
mongoDB modulehttp://drupal.org/project/mongodb
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modules
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cac...
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cac...
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cac...
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cac...
mongoDB module     http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cac...
mongoDB module
mongoDB module
EntityFieldQuery Views       Backendhttp://drupal.org/project/efq_viewsThis module enables Views to useEntityFieldQuery as...
Load into nodes into mongo<?php// Connect$mongo = new Mongo();// Get the database (it is created automatically)$db = $mong...
code sample# drush php-script mongoimport.php# use testDatabase;# db.nodes.find( {title: /Distineo/i} , {title: true}).lim...
code sample# drush php-script mongoimport.php# use testDatabase;# db.nodes.find( {title: /Distineo/i} , {title: true}).lim...
Where mongo won’t      workJoining across Entitiesex. return birthday from profilebelonging to author of current node
DEMO
Q&A
Thanks for you patience enjoy rest of the day!           :-)
Upcoming SlideShare
Loading in …5
×

Optimize drupal using mongo db

9,872 views

Published on

Presentation from DrupalCamp Vancouver 2012.

Published in: Technology

Optimize drupal using mongo db

  1. 1. optimize Drupal using mongoDB
  2. 2. agendalet’s get startedwhat is problem that we face (or what we need/want)sql - relational databasesshift of technologies - noSQL databasesmongoDB - what is mongohow to install mongofinally - drupal & mongomongoDB module - what we can do with itbenefitsq&a
  3. 3. about mename: Vladimir Ilicemployed at: OWFGemail: v_ilic@hotmail.comt witter: burgerboydaddy
  4. 4. Who should be here instead of me
  5. 5. Who should be here instead of me
  6. 6. Who should be here instead of me
  7. 7. what is problem that we faceor what we want to achievewith Drupal based solutions
  8. 8. what is problem that we faceor what we want to achievewith Drupal based solutions speed
  9. 9. what is problem that we faceor what we want to achievewith Drupal based solutions speed scale
  10. 10. what is problem that we faceor what we want to achievewith Drupal based solutions speed scale simplicity
  11. 11. how we can do that?or how to speedup Drupalserver side install Varnish for caching pages for anonymous users. install a persistent cache system (Memcached, APC, Memcache). use a CDN such as Akamai to ser ve static files (JavaScript, CSS, images).
  12. 12. how to speedup drupal - code sideuse Pressflow, it allows Varnish to serve cached page foranonymous users.clean Drupals watchdog table. Every time a watchdogerror gets logged, it consumes CPU resources on the webser ver and database server. It also increases load timesignificantly.implement static and persistent cache strategies until theslow query log comes up clean.avoid PHP errors that occur within nested foreach loops atall costs.uninstall unused modules.turn on caching for Drupal core blocks and Views.
  13. 13. how to speedup drupal - database sideDrupal sites live or die by their database.make sure the tables are properlyindexed for faster searching.do not store unnecessary records, a 100node database will be always accessedfaster than a 3 million node database.change how/where you store your data
  14. 14. speed -shift of technologiesfrom Pentium 100MHz, 16MB RAM,200 MB HDD tomy cell phone: dual core 1GHz, 1GB RAM,32GB storageor maybe some cloud ser ver with 32+CPU’s, few TB RAM, ...
  15. 15. our database technology
  16. 16. our database technology
  17. 17. our database technology1974 - Therelationaldatabase is created
  18. 18. sql - relational dbs
  19. 19. sql - relational dbs1979
  20. 20. sql - relational dbs1979 1982-1996
  21. 21. sql - relational dbs1979 1982-1996 1995
  22. 22. simplicity?relational database model for eCommerce app
  23. 23. simplicity?relational database model for eCommerce app
  24. 24. simplicity?* joins* joins* joins relational database model for eCommerce app
  25. 25. real life example sell groceriesProduct { General Productid: attributesUPC:brand:description:MSRP:price:in-stock:...PLU: 4011unit of measure: lb Item Specificorigin: BC attributesseasonal: yes...
  26. 26. real life example - but we also sell booksProduct {id: General ProductUPC: attributes staybrand:description: the sameMSRP:price:in-stock:...author: Isaac Asimov Book Specifictitle: Foudation’s Edge attributes arebinding: Paperbackpublication date: 1982 differentpublisher name: Spectranumber of pages: 480ISBN: 0553293389
  27. 27. real life example - ops, we want moreProduct { General Productid: attributes stay theUPC: samebrand:description:MSRP:price:in-stock:... Clothing specificbrand: Lee attributes aregender: Mens totally different ...make: Vintagestyle: Straight Cut and not consistentlength: 34 across brands &width: 42 makecolor: Blackmaterial: Cotton...
  28. 28. Now we’re screwed
  29. 29. Now we’re screwed
  30. 30. shift of technologies - db solutionsfrom well-established relational databases to NoSQLtechnologies.NoSQL was first introduced as concept in 1998, it reallywasn’t until 2009 that it emerged as a real trend.NoSQL solutions arent replacements traditionalsolutions, but rather address a specific need in additionto what one might get from traditional offerings.In 90% of the time you’ll probably implement a hybridsystem.put simply, NoSQL is about being open and aware ofalternative, existing and additional patterns and toolsfor managing your data.
  31. 31. shift is happening now few years ago (and still now) MySQL was the undisputed king of the open-source database hill. It is still growing with great speed (40% compound annual grow rate) but There are some competitors that are emerging and grow even faster.
  32. 32. shift is happening now
  33. 33. shift is happening now
  34. 34. shift is happening now451 Research notes:"NoSQL database technologies are largely being adopted fornew projects that require additional scalability,performance, relaxed consistency and agility."
  35. 35. shift is happening now451 Research notes:"NoSQL database technologies are largely being adopted fornew projects that require additional scalability, in other words:performance, relaxed consistency and agility." web :-)
  36. 36. the NoSQL ecosystem
  37. 37. what is Not Only SQL?
  38. 38. what is Not Only SQL?•Non-Relational •Schema-Free•Distributed •Replication Support•Open-Source •Simple API•Horizontally •Eventually Scalable Consistent
  39. 39. mongoDB agile and scalableDB designed for todayMongoDB (from "humongous") is ascalable, high-performance, open sourceNoSQL database.
  40. 40. what is mongo Application Document Oriented High { author: “vladimir”, date: new Date(), text: “drupal-MongoDB...”,Performance tags: [“tech”, “database”]} Fully Consistent Horizontally Scalable
  41. 41. other features of MongoDB Document-based queries Flexible document queries expressed in JSON/Javascript. Map Reduce Flexible aggregation and data processing. Queries run in parallel on all shards. GridFS Store files of any size easily. Geospatial Indexing Find object based on location. (i.e. find closest n items to x) Many Production Deployments
  42. 42. what is mongoDocument oriented storage JSON-style documents with dynamic schemas offer simplicity and power.Full index support (+geo) Index on any attribute, just like youre used to.Replication and High Availability Mirror across LANs and WANs for scale and peace of mind.Querying Rich, document-based queriesFast In-Place UpdatesMap/Reduce
  43. 43. mongoDB philosophyKeep functionality when we can (key/value stores are great, but we needmore)Non-relational (no joins) makes scalinghorizontally practicalDocument data models are goodDatabase technology should runanywhere VMs, cloud, etc
  44. 44. 6 mongoDB conceptsMongoDB has the same concept of a d atabase withwhich you are likely already familiar (or a schemafor you Oracle folks). Within a MongoDB instanceyou can have zero or more databases, each actingas high-level containers for everything else.A database can have zero or more c ollections. Acollection shares enough in common with atraditional table that you can safely think of thet wo as the same thing.Collections are made up of zero or more documents.Again, a document can safely be thought of as arow.
  45. 45. 6 mongoDB conceptsA document is made up of one or more fields, which youcan probably guess are a lot like c olumns.Indexes in MongoDB function much like their RDBMScounterparts.Cursors are different than the other five concepts butthey are important enough, and often overlooked, thatI think they are worthy of their own discussion. Theimportant thing to understand about cursors is thatwhen you ask MongoDB for data, it returns a cursor,which we can do things to, such as counting or skippingahead, without actually pulling down data.
  46. 46. our eCommerce problem again
  47. 47. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"), ‘state’: ‘cart’, ‘line_items’: [ {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 }, {‘UPC’: ‘2348751987’, ‘name’: ‘bananas’, ‘weight’: 3.5, ‘UOM’: kg, ‘retail_price’: 2.75 }, ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’, ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ } ‘subtotal’: 13.74 }
  48. 48. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 }, {‘UPC’: ‘2348751987’, ‘name’: ‘bananas’, ‘weight’: 3.5, ‘UOM’: kg, ‘retail_price’: 2.75 }, ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’, ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ } ‘subtotal’: 13.74 }
  49. 49. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },Embedding {‘UPC’: ‘2348751987’,- Analogous to a foreign key ‘name’: ‘bananas’, ‘weight’: 3.5,- Can be ‘UOM’: kg, - sub objects }, ‘retail_price’: 2.75 - collections ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’, ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ } ‘subtotal’: 13.74 }
  50. 50. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },Embedding {‘UPC’: ‘2348751987’,- Analogous to a foreign key ‘name’: ‘bananas’, ‘weight’: 3.5,- Can be ‘UOM’: kg, - sub objects }, ‘retail_price’: 2.75 - collections ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’, ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ } ‘subtotal’: 13.74 }
  51. 51. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },Embedding {‘UPC’: ‘2348751987’,- Analogous to a foreign key ‘name’: ‘bananas’, ‘weight’: 3.5,- Can be ‘UOM’: kg, - sub objects }, ‘retail_price’: 2.75 - collections ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’, ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ } ‘subtotal’: 13.74 }
  52. 52. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },Embedding {‘UPC’: ‘2348751987’,- Analogous to a foreign key ‘name’: ‘bananas’, ‘weight’: 3.5,- Can be ‘UOM’: kg, - sub objects }, ‘retail_price’: 2.75 - collections ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’,References ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ - Analogous to a foreign key } - Think “relationship” ‘subtotal’: 13.74 }
  53. 53. our eCommerce problem again { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"),Document ‘state’: ‘cart’,- Analogous to a row in RDBMS ‘line_items’: [- Represented as JSON (BSON) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },Embedding {‘UPC’: ‘2348751987’,- Analogous to a foreign key ‘name’: ‘bananas’, ‘weight’: 3.5,- Can be ‘UOM’: kg, - sub objects }, ‘retail_price’: 2.75 - collections ], ‘shipping_address’: { ‘street’: ‘1245 76 Ave.’,References ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 1K8‘ - Analogous to a foreign key } - Think “relationship” ‘subtotal’: 13.74 }
  54. 54. and some basic operationsQueryingAll the following queries will find the document. { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), ‘customer_id’: ObjectId("4fc19d5e5eec78a34f24653d"), ‘state’: ‘cart’,By property value ‘line_items’: [ db.orders.find({‘state’: ‘cart’}) {‘UPC’:885909377275’, ‘name’: ‘Tide HE’, ‘quantity’: 2, ‘tax’: ‘HST’, ‘retail_price’: 10.99 },By embedded object property value {‘UPC’: ‘2348751987’, ‘name’: ‘bananas’, db.orders.find({‘shipping_address.province’: ‘BC’}) ‘weight’: 3.5, ‘UOM’: kg, ‘retail_price’: 2.75 }, ],With comparison operators ‘shipping_address’: { ‘street’: ‘12345 76 Ave.’, db.orders.find({‘subtotal’: {$gt: 10}) ‘city’: ‘Surrey’, ‘province’: ‘BC’, ‘postal code’: ‘V1Q 4K0‘ }Values in collections (implicit “in”) ‘subtotal’: 13.74 } db.orders.find({‘line_items.UPC’: ‘885909377275’})
  55. 55. how to install mongoyou can have mongo on virtually any platform(Windows, OS X, Linux, Solaris, FreeBSD)mongo on Ubuntu in less than 5min add the 10gen GPG key sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 Open document /etc/apt/sources.list (sudo vim /etc/ apt/sources.list). Add at the bottom deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen Update source list and install package sudo apt-get update sudo apt-get install mongodb-10gen
  56. 56. basic mongo commands db.help() -- also db.help (no parentheses) show dbs -- show databases use -- for selecting database db.getCollectionNames() Since collections are schema-less, we dont explicitly need to create them. We can simply insert a document into a new collection. To do so, use the insert command, supplying it with the document to insert.
  57. 57. basic mongo commands use learn <--- switched to db learn > db.getCollectionNames() [ ] > db.starwars.insert({name: C-3PO, gender: robot, position: Protocol droid, homeworld: Tatooine}) > db.getCollectionNames() [ "starwars", "system.indexes" ] What youre seeing is the name of the index, the database and collection it was created against and the fields included in the index
  58. 58. basic mongo commands > db.starwars.find() { "_id" : ObjectId("4fc19d5e0ddc54e49b84928c"), "name" : "C-3PO", "gender" : "robot", "position" : "Protocol droid", "homeworld" : "Tatooine" } > db.system.indexes.find() { "v" : 1, "key" : { "_id" : 1 }, "ns" : "learn.starwars", "name" : "_id_" }
  59. 59. Drupal & mongoIn Drupal 7 if you use field API you want your fields insidemongodb. If you store them inside sql you cannot query themefficiently.Storing data into SQL will crete cases where you will run intodenormalization issues, and with mongo that will be solved.In Drupal 7 everything is entity; nodes are entity, users areentity, comments are entity.We only need few system tables in MySQL that are hard-wired with core drupal; but those things are cached(memcache)everything else can go to mongo. and they (mongo &memcache) are easy to scale.
  60. 60. mongoDB modulehttp://drupal.org/project/mongodb
  61. 61. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modules
  62. 62. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cache items in mongodb.
  63. 63. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cache items in mongodb.mongodb_field_storage: Store the fields in mongodb.
  64. 64. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cache items in mongodb.mongodb_field_storage: Store the fields in mongodb.mongodb_session: Store sessions in mongodb.
  65. 65. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cache items in mongodb.mongodb_field_storage: Store the fields in mongodb.mongodb_session: Store sessions in mongodb.mongodb_watchdog: Store watchdog messages inmongodb
  66. 66. mongoDB module http://drupal.org/project/mongodbmongodb: support library for the other modulesmongodb_cache: Store cache items in mongodb.mongodb_field_storage: Store the fields in mongodb.mongodb_session: Store sessions in mongodb.mongodb_watchdog: Store watchdog messages inmongodbmongodb_block: Store block information inmongodb.Very close to the core block API.
  67. 67. mongoDB module
  68. 68. mongoDB module
  69. 69. EntityFieldQuery Views Backendhttp://drupal.org/project/efq_viewsThis module enables Views to useEntityFieldQuery as the querybackend, allowing you to query alldefined entity types and their fields,even the ones stored in non-sqlstorage such as mongodb.
  70. 70. Load into nodes into mongo<?php// Connect$mongo = new Mongo();// Get the database (it is created automatically)$db = $mongo->testDatabase;// Get the collection for nodes (it is created automatically)$collection = $db->nodes;// Get a listing of all of the node IDs$r = db_query(SELECT nid FROM {node});// Loop through all of the nodes...foreach($r as $row) { print "Writing node $row->nidn"; // Load each node and convert it to an array. $node = (array)node_load($row->nid); // Store the node in MongoDB $collection->save($node); }?>
  71. 71. code sample# drush php-script mongoimport.php# use testDatabase;# db.nodes.find( {title: /Distineo/i} , {title: true}).limit(4);
  72. 72. code sample# drush php-script mongoimport.php# use testDatabase;# db.nodes.find( {title: /Distineo/i} , {title: true}).limit(4);// how to use mongo in php code<?php// Connect$mongo = new Mongo();// Write our search filter (same as shell example above)$filter = array( title => new MongoRegex(/Distineo/i),);// Run the query, getting only 5 results.$res = $mongo->testDatabase->nodes->find($filter)->limit(5);// Loop through and print the title of each article.foreach ($res as $row) { print $row[title] . PHP_EOL;}?>
  73. 73. Where mongo won’t workJoining across Entitiesex. return birthday from profilebelonging to author of current node
  74. 74. DEMO
  75. 75. Q&A
  76. 76. Thanks for you patience enjoy rest of the day! :-)

×