VOOZH about

URL: https://www.geeksforgeeks.org/python/python-mongodb-delete_many/

โ‡ฑ Python Mongodb - Delete_many() - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Mongodb - Delete_many()

Last Updated : 12 Jul, 2025

MongoDB is a general-purpose, document-based, distributed database built for modern application developers and the cloud. It is a document database, which means it stores data in JSON-like documents. This is an efficient way to think about data and is more expressive and powerful than the traditional table model.

Delete_many()

Delete_many() is used when one needs to delete more than one document. A query object containing which document to be deleted is created and is passed as the first parameter to the delete_many().

Syntax:

collection.delete_many(filter, collation=None, hint=None, session=None)

Parameters: 

  • โ€˜filterโ€™ : A query that matches the document to delete.
  • โ€˜collationโ€™ (optional) : An instance of class: โ€˜~pymongo.collation.Collationโ€™. This option is only supported on MongoDB 3.4 and above.
  • โ€˜hintโ€™ (optional) : An index to use to support the query predicate. This option is only supported on MongoDB 3.11 and above.
  • โ€˜sessionโ€™ (optional) : a class:โ€™~pymongo.client_session.ClientSessionโ€™.

 Sample Database: 

๐Ÿ‘ python-mongodb-delete-many-1

 Example 1: Deleting all the documents where the name starts with 'A'. 

Output:

2 documents deleted !!

MongoDB Shell: 

๐Ÿ‘ python-mongodb-delet-many-2

 Example 2: 

Output:

1 documents deleted !!

MongoDB Shell:

๐Ÿ‘ python-mongodb-delete-many-3
 

Comment
Article Tags: