Python MongoDB ডকুমেন্ট সরিয়ে দিন

ডকুমেন্ট সরিয়ে দিন

কোনো ডকুমেন্ট সরিয়ে দিতে আমরা ব্যবহার করি delete_one() Method.

delete_one() প্রথম পারামিটার হল query অবজেক্ট, যা সরিয়ে দিতে হলে ডকুমেন্ট নির্দিষ্ট করে。

মন্তব্য:যদি কোনো কোনো ডকুমেন্ট পাওয়া যায়, তবে শুধুমাত্র প্রথম মিলিয়েছের নাম সরিয়ে দিন。

ইনস্ট্যান্স

ডকুমেন্ট "Mountain 21" এর ঠিকানা সরিয়ে দিন:

import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
myquery = { "address": "Mountain 21" }
mycol.delete_one(myquery)

ইনস্ট্যান্স চালু করো

Delete multiple documents

To delete multiple documents, use delete_many() Method.

delete_many() The first parameter of the method is a query object, used to define the documents to be deleted.

ইনস্ট্যান্স

Delete all documents that start with the letter S in the address:

import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
myquery = { "address": {"$regex": "^S"} }
x = mycol.delete_many(myquery)
print(x.deleted_count, " documents deleted.")

ইনস্ট্যান্স চালু করো

Delete all documents in the collection

To delete all documents in the collection, pass an empty query object to delete_many() পদ্ধতি:

ইনস্ট্যান্স

Delete all documents from the "customers" collection:

import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
x = mycol.delete_many({})
print(x.deleted_count, " documents deleted.")

ইনস্ট্যান্স চালু করো