Support Topics Documentation Slack YouTube Blog

Social media feed

(SnakeEyes) #1

I have the following db model

A Restaurant has a location, many comments, max of 3 tags, and an owner who has a reputation.

I am basically displaying a feed of data to users based on their location. Is there a way I can get all restaurants around me with each restaurant having all the 3 tags, Count(comments), the owner information and the owner reputation ?

Can this be done in one query ? and if not then how are cases like that handled ( think social media feed where for every row you need to pull information from different tables)?

Thank you

(Mark Piller) #2


All doc links are for REST, switch the SDK in the docs to see the corresponding APIs.

To retrieve restaurants around you, you’d use search by distance. Tags, comments and the owner information would be retrieved as relations (either with the single-step retrieval or with the two-step retrieval).

To get the count for the comments, you can see the aggregate function API.


(SnakeEyes) #3

Hi Mark,
Thank you. So I need to do these over multiple queries then, right? Basically I need to find restaurants through search by distance. Then loop through each restraurant and send a seperate request to get Tags, commend and owner information. Is this correct? Theoritically this would work but wouldn’t it take long time compared to one query ? I was hoping there is q eury that can get relations of relations based on geo

(Sergey Kukurudzyak) #4

you can do it using one query with single-step retrieval. you have to find in the Restaurant table with a query that contains distance

(SnakeEyes) #5

Single step retrieval loads related objects, how can I include a Count(comments) as per my question above?

(Sergey Chupov) #6

You probably can do that by specifying count(comments.objectId) as commentsCount as one of the properties field of the query (or props query parameter if you use REST API). This way you’ll receive a field commentsCount for each Restaurant object containing a number of Comments related.

(SnakeEyes) #7

Great! Thank you. I will try it and let you know if I have further questions