Hello Developers,
Hope you are fine. I am new here. I want to convert a MySQL query in MongoDB statement, please help me. My query is…
SELECT DISTINCT f1.*
FROM followers AS f1
INNER JOIN followers AS f2 on f1.user_id=f2.follower_id and f1.follower_id = f2.user_id
where f1.user_id=any user Id.
The following links has information and examples about how to map SQL to MongoDB - both the terminology and the queries. You will be using an Aggregation query to convert the SQL query.
Rather than directly translating your MySQL schema and queries into MongoDB, I would encourage you to consider the best data model to suit your use case. As @Doug_Duncan mentioned, there are other options in MongoDB (such as embedding) which may offer better performance and less complex queries for common use cases.
Some helpful starting points for learning more about data modelling in MongoDB are:
If you do have a question about querying in MongoDB, please provide more information to help others understand what you are trying to achieve: version of MongoDB server, example documents, desired outcome, and what you have tried.
Actually I have a followers collection. I have put document with user_id and follower_id . I want to find all friends of a user X . (Condition For friend : all user follow to user X and X follow to all these users. ) .
I hope you understand my condition.