'How to get metadata / schema of mongodb with all field name and its type in python / pymongo?

I am looking for a python solution where so far I used pymongo and able to retrieve databases, collections. Now it is a challenge to fetch field name and its type. Most of the solution I found on internet suggests to iterate on each document and determine. It would be better if any other optimised solution is available.

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source