Professional Documents
Culture Documents
UNIVERSITY OF TUNIS
Exercise 1:
A video store owner has a relational database to store information about: Film,
actors, producer. The relational schema is as below:
Play(#idfilm,#idActor)
{
"id":123
"title": "Taxi driver",
"category": "drama",
"country": "USA",
"year": 1976,
"director": {
"id":"D123",
"last_name": "Scorcese",
first_name: "Martin",
"birth_date": "1962"
},
"actors": [
{
"id":"A154",
"first_name": "Jodie",
"last_name": "Foster",
"birth_date": null,
}
{
"id":"A155",
first_name: "Robert",
"last_name": "De Niro",
"birth_date": "1943",
"role": "Travis Bickle ",
}
]
}
TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS
db.video_store.insert(
[{
id:123,
title: "Taxi driver",
category: "drama",
country: "USA",
year: 1976,
director: {
id:"D123",
last_name: "Scorcese",
first_name: "Martin",
birth_date: "1962"},
actors: [
{
id:"A154",
first_name: "Jodie",
last_name: "Foster",
birth_date: null},
{
id:"A155",
first_name: "Robert",
last_name: "De Niro",
birth_date: "1943",
role: "Travis Bickle"}
]
}
]
)
3. Insert suitable information (two ways).
1st way
db.video_store.insertOne({
2nd way
db. video_store.createIndex(
db. video_store.find().pretty()
Exercise 2:
We have a collection called “Product”.
Product id
Product name
Product category
Quantity
Price
Cosmetic
Hygiene
Textile
…
1. Propose an adequate structure of NoSQL data base.
2. Use Mongodb to create Product collection and its document(s)
based on the structure that you proposed in question 1.
TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS
db.Products.insertMany ([
{id:100,name:"milk",category:"food",quantity:150,price:"1.500"},
{id:123,name:"l'oreal",category:"Hygiene",quantity:100,price:"10.25
0"},
{id:453,name:"pant",category:"textile",quantity:1000,price:"35.900"
},
{id:284,name:"tshirt",category:"textile",quantity:850,price:"28,950"
},
])
1st way
2nd way
db.Product.find({$and:[{name:/^S.*/i},{quantity:{$lt:40}}]})
{ $sort: { averageOrderQuantity: -1 } }] )