Movatterモバイル変換


[0]ホーム

URL:


Open In App

Usingdrop() method we can drop collection if collection exists. If collection is not found then it returns False otherwise it returns True if collection is dropped. 

Syntax:

drop()

Example 1: 

The sample database is as follows: 

 

Python3
importpymongoclient=pymongo.MongoClient("mongodb://localhost:27017/")# Database namedb=client["mydatabase"]# Collection namecol=db["gfg"]# drop collection col1print(col.drop())

Output: 

Example 2: If collection does not exist. 
 

Python3
importpymongoclient=pymongo.MongoClient("mongodb://localhost:27017/")# Database namedb=client["mydatabase"]# Collection namecol=db["gfg"]# drop collection col1ifcol.drop():print('Deleted')else:print('Not Present')

Output:

Not Present

Improve
Improve
Article Tags :

Explore

Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp