expressivity and complexity of mongodb queries
play

Expressivity and Complexity of MongoDB queries Elena Botoeva - PowerPoint PPT Presentation

Expressivity and Complexity of MongoDB queries Elena Botoeva Faculty of Computer Science, Free University of Bozen-Bolzano, Italy joint work with Diego Calvanese, Benjamin Cogrel, and Guohui Xiao Elena Botoeva(FUB) Expressivity and Complexity of


  1. Expressivity and Complexity of MongoDB queries Elena Botoeva Faculty of Computer Science, Free University of Bozen-Bolzano, Italy joint work with Diego Calvanese, Benjamin Cogrel, and Guohui Xiao Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 1/22

  2. MongoDB a document database system • Very popular • Stores JSON-like documents • Offers powerful ad hoc query languages Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 2/22

  3. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], "birth": "1926-08-27", "contribs": ["OOP", "Simula"], "death": "2002-08-10", "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  4. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, Keys {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], "birth": "1926-08-27", "contribs": ["OOP", "Simula"], "death": "2002-08-10", "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  5. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], Values "birth": "1926-08-27", "contribs": ["OOP", "Simula"], "death": "2002-08-10", "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  6. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], "birth": "1926-08-27", Literals "contribs": ["OOP", "Simula"], "death": "2002-08-10", "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  7. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], "birth": "1926-08-27", "contribs": ["OOP", "Simula"], "death": "2002-08-10", Nested Objects "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  8. Example: JSON document From a collection (of documents) about distinguished computer scientists { "_id": 4, "awards": [ {"award": "Rosing Prize", "year": 1999}, {"award": "Turing Award", "by": "ACM", "year": 2001}, {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"} ], Arrays "birth": "1926-08-27", "contribs": ["OOP", "Simula"], "death": "2002-08-10", "name": {"first": "Kristen", "last": "Nygaard"} } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 3/22

  9. Example: Find query db.bios.find( {$and: [ {"awards.year": {$eq: 1999}} , {"name.first": {$eq: "Kristen"}} ]}, {"name": true , "birth": true} ) Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 4/22

  10. Example: Find query db.bios.find( {$and: [ {"awards.year": {$eq: 1999}} , {"name.first": {$eq: "Kristen"}} ]}, {"name": true , "birth": true} ) When evaluated over the document about Kristen Nygaard: { "_id": 4, "birth": "1926-08-27", "name": { "first": "Kristen", "last": "Nygaard" } } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 4/22

  11. Example: Aggregation Framework query Retrieves scientists who received two awards in the same year. db.bios.aggregate ([ {$project: { "name": true , "award1": "$awards", "award2": "$awards" } }, {$unwind: "$award1"}, {$unwind: "$award2"}, {$project: { "name": true , "award1": true , "award2": true , " twoInOneYear ": { $and: [ {$eq: ["$award1.year", "$award2.year"]}, {$ne: ["$award1.award", "$award2.award"]} ]} }}, {$match: { " twoInOneYear ": true } }, ]) Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 5/22

  12. Example: Aggregation Framework query Retrieves scientists who received two awards in the same year. db.bios.aggregate ([ {$project: { "name": true , "award1": "$awards", "award2": "$awards" } }, {$unwind: "$award1"}, {$unwind: "$award2"}, {$project: { "name": true , "award1": true , "award2": true , " twoInOneYear ": { $and: [ {$eq: ["$award1.year", "$award2.year"]}, {$ne: ["$award1.award", "$award2.award"]} ]} }}, {$match: { " twoInOneYear ": true } }, ]) When evaluated over the document about Kristen Nygaard: { "_id": 4, "name": {"first": "Kristen", "last": "Nygaard"} "award1": {"award": "Turing Award", "by": "ACM", "year": 2001}, "award2": {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"}, "twoInOneYear": true } Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 5/22

  13. Example: Aggregation Framework query Retrieves scientists who received two awards in the same year. db.bios.aggregate ([ {$project: { "name": true , "award1": "$awards", "award2": "$awards" } }, {$unwind: "$award1"}, {$unwind: "$award2"}, {$project: { "name": true , "award1": true , "award2": true , " twoInOneYear ": { $and: [ {$eq: ["$award1.year", "$award2.year"]}, {$ne: ["$award1.award", "$award2.award"]} ]} }}, {$match: { " twoInOneYear ": true } }, ]) When evaluated over the document about Kristen Nygaard: { "_id": 4, "name": {"first": "Kristen", "last": "Nygaard"} "award1": {"award": "Turing Award", "by": "ACM", "year": 2001}, "award2": {"award": "IEEE John von Neumann Medal", "year": 2001, "by": "IEEE"}, "twoInOneYear": true } This query performs a join within a document . Elena Botoeva(FUB) Expressivity and Complexity of MongoDB queries 5/22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend