Home Code List all collections in a MongoDB Database using PyMongo

List all collections in a MongoDB Database using PyMongo

Script to list the names of all collections in a given MongoDB database using PyMongo.

from pymongo import MongoClient

#connect to local mongodb instance
client = MongoClient('localhost',27017)

#get the required mongodb database
db = client['my_db']

#get the list of all MongoDB collections in the database
collections = [collection_name for collection_name in db.list_collection_names()]
Content Protection by DMCA.com
Gurudevhttps://www.hitxp.com
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

4,258FansLike
7FollowersFollow
133FollowersFollow
380FollowersFollow

Subscribe to HitXP Articles

To be updated with all the latest articles, offers and special announcements.

Latest Articles

Corona Virus, SARS – Why are new viruses increasingly originating from China?

The reason why new strains of deadly viruses are emerging from China. Viruses like coronavirus and SARS should be stopped from evolving and spreading to prevent another global pandemic.

Evolution of life – primitive cells, complex organisms, intelligence, what next after humans?

Evolution of life from primitive life forms to complex multi cellular organisms to intelligent human species - the advent of AI raises a natural question - What next after human?

The individual human is smart, but the human species is dumb

The smart individual human has to clean up the mess created by his dumb species. Species polluted the planet, individuals are cleaning it up.

What if Dinosaurs did not go extinct 65 million years ago?

Imagine a world where dinosaurs did not go extinct, because that asteroid missed colliding with Earth. How would have life evolved then?
Content Protection by DMCA.com