• Non ci sono risultati.

Part 2 - MongoDB

N/A
N/A
Protected

Academic year: 2021

Condividi "Part 2 - MongoDB"

Copied!
2
0
0

Testo completo

(1)

Data Science and Database Technology

Politecnico di Torino

NoSQL in MongoDB – Practice 6 - 2

Part 2 - MongoDB

Running queries of interest

Run the following queries of interest:

1) Find all restaurants whose cost is medium

2) Find all restaurants whose review is bigger than 4 and cost is medium or low 3) Find all restaurants that can contain more than 5 people and:

a. whose tag contains "italian" or "japanese" and cost is medium or high OR

b. whose tag does not contain neither "italian" nor "japanese", and whose review is higher than 4.5

4) Calculate the average review of all restaurants

5) Count the number of restaurants whose review is higher than 4.5 and can contain more than 5 people

6) Run query n. 4 using the Map-Reduce paradigm 7) Run query n.5 using the Map-Reduce paradigm

8) Find the restaurant in the collection which is nearest to the point [45.0644, 7.6598]

Hint: remember to create the geospatial index.

9) Find how many restaurants in the collection are within 500 meters from the point [45.0623, 7.6627]

Queries’ solution and expected output

1) db.restaurants.find({"cost":"medium"}).pretty()

2) db.restaurants.find({review:{$gt:4},$or:[{cost:"medium"},{cost:"low"}]}).pre tty()

(2)

3) db.restaurants.find({$or:[{$or:[{tag:"italian"},{tag:"japanese"}],$or:[{cost:"

medium",cost:"high"}]},{tag:{$ne:"italian"},tag:{$ne:"japanese"},review:{$gt :4.5}}],maxPeople:{$gt:5}})

4) db.restaurants.aggregate([{$group:{_id:null,review_avg:{$avg:"$review"}}}]) -> { "_id" : null, "review_avg" : 4.26 }

5) db.restaurants.aggregate([{$match:{review:{$gt:4.5},maxPeople:{$gt:5}}},{

$group:{_id:null,count:{$sum:1}}}])

6) db.restaurants.mapReduce(function() {emit(null, this.review);},function(key, values) {return Array.avg(values);},{out:"restaurants_reviews_avg"})

db.restaurants_reviews_avg.find()

7) db.restaurants.mapReduce(function() {emit(null, 1);},function(key, values) {return Array.sum(values);},{query: { review:{$gt:4.5},maxPeople:{$gt:5}}, out: "restaurants_reviewsGT5_maxPGT5"})

8) db.restaurants.createIndex({location: "2dsphere"})

db.restaurants.findOne({location:{$near:{$geometry:{type:

"Point",coordinates: [45.0644,7.6598]}}}})

9) db.restaurants.createIndex({location: "2dsphere"})

db.restaurants.find({location:{$near:{$geometry:{type: "Point",coordinates:

[45.0623,7.6627]},$maxDistance: 500}}}).count()

Riferimenti

Documenti correlati

NOTE: In the solution of a given exercise you must (briefly) explain the line of your argument and show the main points of your calculations1. Solutions without adequate

However, the latter possibility is ruled out by the fact that A is supposed to be symmetric, hence its eigenvalues need to be real.. Moreover, since A is symmetric, the eigenvectors

Note that such D’s are precisely those wich are not contained in the linear span L(A, B). To find concretely such a D the shortest

Solution proposed by Roberto Tauraso, Dipartimento di Matematica, Universit`a di Roma “Tor Vergata”, via della Ricerca Scientifica, 00133 Roma,

Answer: As a basis of Im A, take the first, fourth and fifth columns, so that A has rank 3. Find a basis of the kernel of A and show that it really is a basis... Does the union of

If S is not a linearly independent set of vectors, remove as many vectors as necessary to find a basis of its linear span and write the remaining vectors in S as a linear combination

People in low-wage jobs, however, are more likely than those in higher-quality occupations to exit the labor force or become unemployed, and, troublingly, only 5.2 percent moved

Current understanding, based on the noticeable, small, truly congenital nevi and nevi acquired early in life, is that the first develops before puberty, presents with a