Is there anyway to create view using python

Hello everyone, I am a beginner in mongoDB. I am developing an application using mongoDB with python and I am currently struggled with some problem. I have been manually creating a view using mongo compass before, but I realized that my system should automatically create a view when I create a collection using python. Is there anyway to solve this problem ( I have looked in stackoverflow 5 years ago and they said there is no libraries for that)?.

Views are created programmatically by operations like mongosh db.createView()

In short, it’s a $lookup a $match and a $project

See pymongo.database.create_collection() … views are there in the notes. It’s all done in the kwargs to the function.

1 Like

I edited my previous reponse quite a bit, @Nattapol_Chiewnawintawat … hope you got the latest :grin:

In addition, you may find this page helpful: