Open henryliangt opened 1 year ago
MATCH(a:Person)-[:ACTED_IN]->(m:Movie{title:"A Few Good Men"})
MATCH(d:Person)-[:DIRECTED]->(m)
WHERE a.born<d.born
RETURN a.name as name, d.born-a.born as age difference
ORDER BY age difference
DESC
MATCH(t:Person{name:"Tom Hanks"}) MATCH(a:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(t) WHERE m.released <=1995 MATCH (a2:Person)-[:ACTED_IN]->(m2:Movie)<-[:ACTED_IN]-(t) WHERE m2.released > 1995 WITH a, collect(a2) as to_ignore WITH a where not a in to_ignore RETURN a.name as name ORDER BY name
MATCH(p:Person)-[:REVIEWED]->(m:Movie)<-[:ACTED_IN]-(a:Person) WITH a, collect(DISTINCT m.title) as movies where size(movies)>=2 UNWIND movies as movie RETURN a.name as name, movie
Question 1 Short Answer Questions (30 points)
Question 2 MongoDB Queries, Indexing and Read/Write Concern (25 points) All parts of this question are related to a MongoDB database with two collections: tweets and users. The tweets collection contains tweet object similar to the data set we have used in labs and in assignments. The question only involves two types of tweets: a general tweet and a retweet. The following are two example tweet objects representing general tweet and retweets respectively. For simplicity, we omit the _id field
A general tweet object: { "id": 1308517931341484032, "created_at": ISODate("2021-09-22 21:26:00"), "user_id": 28949616, “retweet_count”: 22 }
A retweet object: { "id": 1308517931341489067, "created_at": ISODate("2021-09-23 12:05:43"), "user_id": 127946336, "retweet_id": 1308517931341484032, "retweet_user_id": 28949616 } The users collection contains user object. A user object has an id, name and created_at time. Most users follow many other users. The user ids they follow are stored in an array field called following. Below is an example user document. The _id field is omitted. { "id": 28949616, "name": "Nobody", "created_at": ISODate("2001-03-13 19:33:30"), "following": [1964768, 62370835, …] }
[4 points] Write a query to find all retweets a tweet with id 123 created before “2021-10- 13 19:33:30”, sort the retweets by creation time ascendingly.
[8 points] For a given tweet with id 123, write a query/aggregation to find the number of retweets made by the tweet user’s follower.
[5 points] Assume the following indexes have been created: db.tweets.createIndex({retweet_id:1, created_at:-1}) db.tweets.createdIdex({id:1}) db.users.createIndex({id:1}) Analyse the index usage of your queries in part 1 and part2.
[8 points] Assume the collections are stored in a replica set with 3 members. A tweet with id: 123 has 20 retweet_count. The database receives a command to update the retweet_count to 21. The update was completed at t0 on primary; it was completed at t1 in secondary 1; primary receives the acknowledgment from primary 1 at t2; the update was completed at t3 in secondary 2; secondary 1 receives the notification to update its majority agreed copy at t4; secondary 2 receives the notification to update its majority agreed copy at t5; Describe in detail what would return under the following conditions: a. Read against primary with read concern set to “majority” and the read happens between t1 and t2; b. Read against primary with read concern set to “local” and the read happens between t1 and t2; c. Read against secondary with read concern set to “majority” and the read happens in secondary 1 between t3 and t4 d. Read against secondary with read concern set to “local” and the read happens on secondary 2 between t3 and t
Question 3 Neo4j Data Modeling and Query (25 points) All parts of this question are related with a graph representing units offered in a university and their prohibited and prerequisite relationships. A sample graph is show in Figure 1. Each node in the graph represents a unit. They all have the same label: Unit. A unit can have PROHIBITED or PREREQUISITE relationship with other nodes. Both types of relationships have directions. The graph shows that INFO1110 is the prerequisite of COMP2123 and INFO1905 is prohibited with COMP2123. Most units in the graph have the following properties: code (which is shown in the graph), title and semesters. Below is an example of the properties of a unit with code “INFO1110”: { "code": "INFO1110", "title": "Introduction to Programming", "semesters": ["S1","S2"] }
Question 4 Dynamo (20 points) Suppose we have a Dynamo cluster with 6 nodes: n0~n5. The tokens assigned to each nodes are as follows: n0: 0, 82; n1: 25; n2: 12, 70; n3: 61; n4: 35; n5: 44,90 The maximum ring space value is 99. The cluster has a replication factor of 3; the size of preference list is 4; A table about web pages is stored in this cluster, with keys equal to the page’s URL.
Test