Python MongoDB - find_one_and_delete Query Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report MongoDB is a cross-platform document-oriented and a non relational (i.e NoSQL) database program. It is an open-source document database, that stores the data in the form of key-value pairs. Find_one_and_delete Query This function is used to delete a single document from the collection based on the filter that we pass and returns the deleted document from the collection. It finds the first matching field that matches the filter and deletes it from the collection i.e finds a single document and deletes it, returning the document. Syntax: Collection.find_one_and_delete(filter, projection=None, sort=None, session=None, **kwargs) Parameters: 'filter' : A query that matches the document to delete. 'projection' (optional): A list of field names that should be returned in the result document or a mapping specifying the fields to include or exclude. If 'projection' is a list "_id" will always be returned. Use a mapping to exclude fields from the result (e.g. projection={'_id': False}). 'sort' (optional): A list of (key, direction) pairs specifying the sort order for the query. If multiple documents match the query, they are sorted and the first is deleted. 'session' (optional): A class: "~pymongo.client_session.ClientSession". '**kwargs' (optional): Additional command arguments can be passed as keyword arguments (for example maxTimeMS can be used with recent server versions). Example 1: Sample Database: Python3 1== # importing Mongoclient from pymongo from pymongo import MongoClient # Making Connection myclient = MongoClient("mongodb://localhost:27017/") # database db = myclient["mydatabase"] # Created or Switched to collection # names: GeeksForGeeks Collection = db["GeeksForGeeks"] # Defining the filter that we want to use. Filter ={'Manufacturer': 'Maruti'} # Using find_one_and_delete() function. print("The returned document is:") print(Collection.find_one_and_delete(Filter, projection = None, sort = None)) # Printing the data in the collection # after find_one_and_delete() operation. print("\nThe data after find_one_and_delete() operation is:") for data in Collection.find(): print(data) Output: Example 2: Python3 1== # importing Mongoclient from pymongo from pymongo import MongoClient # Making Connection myclient = MongoClient("mongodb://localhost:27017/") # database db = myclient["mydatabase"] # Created or Switched to collection # names: GeeksForGeeks Collection = db["GeeksForGeeks"] # Defining the filter that we want to use. Filter ={'Manufacturer': 'Hyundai'} # Using find_one_and_delete() function. print("The returned document is:") print(Collection.find_one_and_delete(Filter, projection = None, sort = None)) # Printing the data in the collection # after find_one_and_delete() operation. print("\nThe data after find_one_and_delete() operation is:") for data in Collection.find(): print(data) Output: Comment More infoAdvertise with us V VishwashVishwakarma Follow Improve Article Tags : Python Python-mongoDB Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like