I’m studying Mongodb and I have difficulty in writing the queries of the exercize below, namely point 2. May you help me?
Suppose you want to record in a document-based storage solution a list of scientific articles.
Each article is described by a title, a list of authors with respective affiliation and email, the number of pages, an abstract and the actual content.
Content includes paragraphs, in turn containing text, table and images. Paragraphs can also recursively contain subparagraphs, with the same structure.
An article includes also references to other articles (bibliography). As an example:
{_id: doc1,
Title: “X”, Authors: [{name=“A”, affiliation=“PoliTo”}, {name=“B”, affiliation=“KTH”}], Pages:45, Abstract: “…”,
Content: [{section: “S1”, title: “T1”, text: “…”}, {section: “S2”, title: “T2”, text: “…”, imgs: […] }, …],
Bibliography: [{paper: doc2},{paper: doc3},…]
}
Write the following queries:
- Find the documents written by at least one author from “PoliTo” that contains at least 20 pages
and includes a section titled “Big Data” at any of the 3 top-most section levels
db.inventory.find( {
Authors: {$elementMatch: {affiliation=“Polimi”}}, Pages: {$gte 20}, Content: {$or: [ {section: “S1”, title: “Big Data”}, {section: “S2”, title: “Big Data”}, {section: “S3”, title: “Big Data”} ]}
} )
is it correct ?
- Find the documents that include a reference to another article written by at least one author from “UniTo”
???