0

I am trying to implement a like visualization system for a table of products. I would like to see if user has liked the product. I have a Products table and a Likes table. I can do this in Firestore with transactions but, I would like to use Stitch. Stitch does not offer transactions. Does anyone know if there is anything in the Swift SDK that I am missing? MongoDB Stitch does not have too much of an extensive documentation. I would very much appreciate your help.

user10447655
  • 180
  • 2
  • 10
  • 2
    It seems to me like you might be approaching this with a relational database mentality. Have you looked into MongoDB best practices to find a solution more idiomatic to MongoDB? This article may help: https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1 – Chris Bush Apr 17 '19 at 16:21
  • Thank you. It would require two queries. I was looking to do it in one as it will be used in an infinite table. This means two queries for every fetchMoreData. Do you think it is a bad idea to query all user likes at once and store them? This could be hundreds or thousands of product ids saved locally. If so, should I compress the ids? – user10447655 Apr 17 '19 at 17:37
  • You have options. [$lookup](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/index.html) is available to you in [System Functions](https://docs.mongodb.com/stitch/mongodb/mongodb-service-limitations/#aggregation-limitations); you could embed a users_who_liked_this array in your product document (up to the document size limit of 16MB); as you said, you could download all of the user's likes at once and reference them; or just do two queries. It depends on your specific situation which tradeoff to choose. – Chris Bush Apr 18 '19 at 18:53
  • Thanks. Any idea on [How to get metadata out of AWS Cognito JWT to use it for the MongoDB Stitch Metadata Fields?](https://stackoverflow.com/questions/55667558/how-to-get-metadata-out-of-aws-cognito-jwt-to-use-it-for-the-mongodb-stitch-meta) – user10447655 Apr 20 '19 at 18:45
  • Sorry, I looked at your question about the JWT, but I don't know how to answer. – Chris Bush Apr 26 '19 at 17:10
  • Thank you, anyway. – user10447655 Apr 26 '19 at 17:21

0 Answers0