0

Does anyone know how to translate these 2 queries from PostgreSQL to MongoDB? I don't have any idea from MongoDB but I have to use these 2 lines in my script.

SELECT genres,startYear,COUNT(*) 
FROM title_basics 
GROUP BY genres, "startYear";

SELECT genres,COUNT(genres) 
FROM title_basics 
GROUP BY genres 
ORDER BY COUNT(genres) DESC;

Thank you in advance!

1 Answer 1

1

These are the queries you can use with the mongodb driver inside your code.

db.titles_basics.aggregate([
{"$group" : {genres:"$startYear", count:{$sum:1}}}
])

 db.titles_basics.aggregate([
{"$group" : {genres:"$startYear", count:{$sum:1}}} ,{ $sortByCount: "$genres" }
])

Hope this works and if doesn't try explaining your question a little bit more. Your question is very poorly explained and what i got from it i posted my answer for it. GOOD LUCK :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.