6/11/2023 0 Comments Arangodb qal break for![]() ![]() Moreover, different models can be combined in a single query. Using a multi-model database can simplify your architecture by combining several NoSQL types in a single infrastructure. As applications become increasingly complex, you often need more than one NoSQL database. It supports graph, document, and key-value data models allowing users to freely combine all data models in a single query. It is designed as a “general purpose database,” offering all the features typically needed for modern web apps. LET target_users = (įOR v IN 1.1 OUTBOUND follows RETURN v._idįOR vertices, edges, paths in 1.ArangoDB is an open-source multi-model NoSQL database with a flexible data model for documents and graphs. Here is another more compact version of the query that takes a param, the _id of the user that is 'you'. The first edge in paths.edges is the review that the user made of the place The last vertex in paths.vertices is the end of the path, e.g. The first vertex in paths.vertices is the starting vertex ( users/6327) Merged_reviews: UNION(my_reviews, reviews_of_who_i_follow) Reviews_of_who_i_follow: reviews_of_who_i_follow, LET my_reviews = (įOR vertices, edges, paths IN 1.1 OUTBOUND "users/6327" reviewsįOR v IN 1.1 OUTBOUND "users/6327" followsįOR vertices, edges, paths in 1.1 OUTBOUND users._id reviews Note: When providing an id on each record I used the id of the review, because if you know that id you can fetch the edge document and get the id of both the user and the place as well as read all the data about the review. reviews edge collection tracks reviews people wrote.follows edge collection tracks users following other users.places document collection contains places.users document collection contains users.It is possible to merge these queries together more optimally, but I thought it worth breaking them out like this (and showing the output of each stage as well as the final answer) to help you see what data is available.Ī key thing to understand about AQL graph queries is how you have access to vertices, edges, and paths when you perform a query.Ī path is an object in it's own right and it's worth investigating the contents of that object to better understand how to exploit it for path information. Merge together your reviews with those of the people you follow.Determine the reviews the people you follow have written.I take a different approach below, and that is to: One way is to determine the _id of your user record, then find all the _id's of the friends you follow, and then to work out all related reviews in one query. There are a number of ways to do this query, and it also depends on where you want to add parameters, but for the sake of simplicity I've built this quite verbose query below to help you understand one way of approaching the problem. Review,"review about place 2 from the user I follow" How can I get all the places that I like and the reviews of the people that I follow who also reviewed the same place that I like.Īn expected output would be something like the following: [ I also follow user 6344 which also happens to have reviewed the place 7968. I am user 6327 and I reviewed both places(793) ![]() How can I traverse the graph to fetch all the places that I like with my review of the place and the reviews of the users I follow that also like the same place.įor example, in the above graph. The "likes" edge collection also has a "review" property to store a user's review about the place.Īnd a "follows" edge collection to denote that a user follows another user. Given a collection of "users" and a collection of "places".Īnd a "likes" edge collection to denote that a user likes a certain place. ![]() I am having some trouble wrapping my head around how to traverse a certain graph to extract some data. ![]()
0 Comments
Leave a Reply. |