famous TV show<\/a> \ud83d\ude42<\/p>\n\n\n\n\n\nAll episodes from season 1<\/u><\/p>\n\n\n\nMySQL myHost:33060+ demo JS> db.GoT_episodes.find(\"season=1\").fields(\"name\", \"summary\", \"airdate\").sort(\"number\")\n[\n {\n \"name\": \"Winter is Coming\",\n \"airdate\": \"2011-04-17\",\n \"summary\": \"<p>Lord Eddard Stark, ruler of the North, is summoned to court by his old friend, King Robert Baratheon, to serve as the King's Hand. Eddard reluctantly agrees after learning of a possible threat to the King's life. Eddard's bastard son Jon Snow must make a painful decision about his own future, while in the distant east Viserys Targaryen plots to reclaim his father's throne, usurped by Robert, by selling his sister in marriage.<\/p>\"\n },\n {\n \"name\": \"The Kingsroad\",\n \"airdate\": \"2011-04-24\",\n \"summary\": \"<p>An incident on the Kingsroad threatens Eddard and Robert's friendship. Jon and Tyrion travel to the Wall, where they discover that the reality of the Night's Watch may not match the heroic image of it.<\/p>\"\n },\n {\n \"name\": \"Lord Snow\",\n \"airdate\": \"2011-05-01\",\n \"summary\": \"<p>Jon Snow attempts to find his place amongst the Night's Watch. Eddard and his daughters arrive at King's Landing.<\/p>\"\n },\n {\n \"name\": \"Cripples, Bastards, and Broken Things\",\n \"airdate\": \"2011-05-08\",\n \"summary\": \"<p>Tyrion stops at Winterfell on his way home and gets a frosty reception from Robb Stark. Eddard's investigation into the death of his predecessor gets underway.<\/p>\"\n },\n {\n \"name\": \"The Wolf and the Lion\",\n \"airdate\": \"2011-05-15\",\n \"summary\": \"<p>Catelyn's actions on the road have repercussions for Eddard. Tyrion enjoys the dubious hospitality of the Eyrie.<\/p>\"\n },\n {\n \"name\": \"A Golden Crown\",\n \"airdate\": \"2011-05-22\",\n \"summary\": \"<p>Viserys is increasingly frustrated by the lack of progress towards gaining his crown.<\/p>\"\n },\n {\n \"name\": \"You Win or You Die\",\n \"airdate\": \"2011-05-29\",\n \"summary\": \"<p>Eddard's investigations in King's Landing reach a climax and a dark secret is revealed.<\/p>\"\n },\n {\n \"name\": \"The Pointy End\",\n \"airdate\": \"2011-06-05\",\n \"summary\": \"<p>Tyrion joins his father's army with unexpected allies. Events in King's Landing take a turn for the worse as Arya's lessons are put to the test.<\/p>\"\n },\n {\n \"name\": \"Baelor\",\n \"airdate\": \"2011-06-12\",\n \"summary\": \"<p>Catelyn must negotiate with the irascible Lord Walder Frey.<\/p>\"\n },\n {\n \"name\": \"Fire and Blood\",\n \"airdate\": \"2011-06-19\",\n \"summary\": \"<p>Daenerys must realize her destiny. Jaime finds himself in an unfamiliar predicament.<\/p>\"\n }\n]<\/code><\/pre>\n\n\n\n\n\nFirst episode of each season<\/u><\/p>\n\n\n\nMySQL myHost:33060+ demo JS> db.GoT_episodes.find(\"number=1\").fields(\"name\", \"airdate\", \"season\").sort(\"season\")\n[\n {\n \"name\": \"Winter is Coming\",\n \"season\": 1,\n \"airdate\": \"2011-04-17\"\n },\n {\n \"name\": \"The North Remembers\",\n \"season\": 2,\n \"airdate\": \"2012-04-01\"\n },\n {\n \"name\": \"Valar Dohaeris\",\n \"season\": 3,\n \"airdate\": \"2013-03-31\"\n },\n {\n \"name\": \"Two Swords\",\n \"season\": 4,\n \"airdate\": \"2014-04-06\"\n },\n {\n \"name\": \"The Wars to Come\",\n \"season\": 5,\n \"airdate\": \"2015-04-12\"\n },\n {\n \"name\": \"The Red Woman\",\n \"season\": 6,\n \"airdate\": \"2016-04-24\"\n },\n {\n \"name\": \"Dragonstone\",\n \"season\": 7,\n \"airdate\": \"2017-07-16\"\n },\n {\n \"name\": \"TBA\",\n \"season\": 8,\n \"airdate\": \"2019-04-14\"\n }\n]\n8 documents in set (0.0047 sec)<\/code><\/pre>\n\n\n\n\n\nCRUD Prepared Statements<\/h3>\n\n\n\n
A common pattern with document store datastores is to repeatedly execute the same (or similar) kind of simple queries (e.g. \u00ab\u00a0id<\/em>\u00a0\u00bb based lookup).
These queries can be accelerated using <\/strong>prepared (CRUD) statements<\/strong><\/a>.<\/p>\n\n\n\nFor example if your application often use the following query:<\/p>\n\n\n\n
MySQL myHost:33060+ demo JS> db.GoT_episodes.find(\"number=1 AND season=1\").fields(\"name\", \"airdate\")\n[\n {\n \"name\": \"Winter is Coming\",\n \"airdate\": \"2011-04-17\"\n }\n]<\/code><\/pre>\n\n\n\nSo it’s probably a good idea to use prepared statements.
First we need to prepare the query:<\/p>\n\n\n\n
\/\/ Prepare a statement using a named parameter\nvar gotEpisode = db.GoT_episodes.find(\"number = :episodeNum AND season = :seasonNum\").fields(\"name\", \"airdate\")<\/code><\/pre>\n\n\n\nThen bind the value to the parameter :<\/p>\n\n\n\n
MySQL myHost:33060+ demo JS> gotEpisode.bind('episodeNum', 1).bind('seasonNum', 1)\n[\n {\n \"name\": \"Winter is Coming\",\n \"airdate\": \"2011-04-17\"\n }\n]<\/code><\/pre>\n\n\n\nMySQL myHost:33060+ demo JS> gotEpisode.bind('episodeNum', 7).bind('seasonNum', 3)\n[\n {\n \"name\": \"The Bear and the Maiden Fair\",\n \"airdate\": \"2013-05-12\"\n }\n]<\/code><\/pre>\n\n\n\nSimply powerful!<\/p>\n\n\n\n\n\n
Index<\/h3>\n\n\n\n
Indeed relevant indexes is a common practice to improve performances. MySQL Document Store allows you to index your keys<\/strong> inside the JSON document.<\/p>\n\n\n\nAdd a composite Index on keys season<\/em> AND