Blog

Xóa Document trong MongoDB

Phương thức remove() trong MongoDB

Phương thức remove() trong MongoDB được sử dụng để xóa Document từ Collection. Phương thức remove() nhận hai tham số. Tham số đầu tiên deletion criteria xác định Document để xóa, và tham số thứ hai là justOne.

  1. deletion criteria: (Tùy ý) Xác định Document để xóa.
  2. justOne: (Tùy ý) Nếu được thiết lập là true hoặc 1, thì chỉ xóa một Document.

Cú pháp

Cú pháp cơ bản của phương thức remove() là như sau:

>db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)

Ví dụ

Bạn theo dõi Collection có tên mycol có dữ liệu sau:

{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}

Ví dụ sau sẽ xóa tất cả Document có title là ‘MongoDB Overview’:

>db.mycol.remove({'title':'MongoDB Overview'})
>db.mycol.find()
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
>

Chỉ xóa một Document trong MongoDB

Nếu có nhiều bản ghi và bạn chỉ muốn xóa bản ghi đầu tiên, thì thiết lập tham số justOne trong phương thức remove().

>db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)

Xóa tất cả Document trong MongoDB

Nếu bạn không xác định deletion criteria, thì MongoDB sẽ xóa toàn bộ Document từ Collection. Điều này tương đương với lệnh truncate trong SQL.

>db.mycol.remove()
>db.mycol.find()
>

Leave a Reply

Your email address will not be published. Required fields are marked *

https://jmspc.ac.in/ Tren Komunitas Urban Jakarta: Permainan Papan Klasik ke Adaptasi Mahjong Digital Cara kerja fitur ubin emas terhadap pengguna agar tetap menatap layar berjam-jam Menghindari godaan kombinasi parlay panjang yang sering berujung pada penyesalan Menemukan ritme bermain yang pas agar hobi hiburan digital tidak sampai mengganggu produktivitas kerja Wild West Gold vs Wild Bounty Showdown mana yang sebenarnya lebih ramah untuk dimainkan pemula alasan mengapa fitur scatter hitam selalu sukses memanipulasi rasa penasaran pemain mahjong ways fakta di balik kemenangan pertama dan dampaknya pada pengambilan keputusan lanjutan Kenapa Player Jakarta Kembali Melirik Mahjong Ways 2 di Tengah Gempuran Tren Game Baru Lainnya Alasan Utama Gates of Olympus 1000 Mendadak Kuasai Obrolan Warung Kopi Jakarta Bulan Ini Gema Hiburan yang Menentukan Arah Ritme Permainan Edukasi Cara Kerja Simbol Olympus yang Bikin Banyak Orang Ketagihan Mencoba Apa Perbedaan Mekanika Antara Olympus Klasik dan Versi Upgrade Terbarunya Analis Sebut Mahjong Jadi Pelopor Game Online Masa Kini Pemain Baccarat Jakarta Jadi Perbincangan, Bicara Kemenangan hingga Kesuksesan Cara Mengelola Saldo Harian Agar Sesi Bermain PG Soft Tetap Terkendali Dari Data ke Historis, Menggagas Formasi untuk Hasil Parlay Banyak yang Salah Paham Soal Cara Kerja RTP Baccarat Meski Sering Dimainkan Tiap Hari Rahasia di Balik Pola Ubin Emas yang Bikin Pemain PG Soft Susah Lepas dari Layar Sering Viral di Media Sosial, Begini Sebenarnya Algoritma Gates of Olympus 1000 Bekerja Ternyata Ini Alasan Fitur Scatter Hitam Mahjong Ways Mendadak Ramai Dibicarakan Bulan Ini slot4d slotsensa slot gacor https://www.jmsit.ac.in/placement/ suhubet slot4d https://fabritec.pe/asesor.php https://kibf.pk/ slot4d slot gacor https://www.jms.ac.in/admission-procedure/ slot gacor slot luar negeri slot4d slot gacor 4d totogacor slot4d slot4d slot gacor slot gacor slot gacor https://promo-sign.com/ slot4d demo slot slot thailand slot4d https://www.ugelhuaylas.edu.pe/ slot4d slot4d slot4d https://dulsa.com/ slot4d https://fabritec.pe/see/corporacion/ slot4d https://waterco.co.id/pompa-kolam-renang/ https://cliffcrestinn.com/rates/ https://www.bhagwati.ac.in/academics/ https://seteilhas.com.br/site/ https://umgeg.com/ https://www.paracasoverland.com.pe/ slot gacor slot gacor 4d https://amcstoneandcabinets.com/ totogacor slot gacor wd jutaan https://spingharkabul.edu.af/ https://lpmi.handayani.ac.id/surveyB https://www.jalwadancecompany.com/x-2-3-bhangra-dancers/ https://gaesasa.com/tienda/ https://impactocontable.co/servicios-tributarios-pago-de-impuestos/ https://spingharkabul.edu.af/published-papers/ https://littlebigcat.com/ slot4d https://gaesasa.com/sobre-gaesa/ https://warmihuasi.org/proyectos/ https://coppercoat.com.br/ slot gacor https://www.jetfloweurope.com/ slot gacor https://www.norsal-eg.com/ slot4d https://subhkirancapital.com/ slot gacor https://spingharkabul.edu.af/stomatology/ https://www.balinanny-babbyhire.com/pricing/ https://cliffcrestinn.com/historic-places-to-stay-in-santa-cruz-ca/ https://moalem24.com/ https://pps.handayani.ac.id/ toto 4d https://ekklesiahouses.com/ https://happyspring.com/ https://hitchparts.com/ https://praisevibration.com/ https://bolsecol.com/ https://centrobienser.com/ slot gacor https://www.jalwadancecompany.com/ https://solnascentealimentos.com.br/ https://www.homeofenglish.edu.kh/ https://www.balinanny-babbyhire.com/ https://warmihuasi.org/ https://gaesasa.com/blog/ https://gaesasa.com/shop/ https://www.blccampus.edu.lk/ https://warmihuasi.org/enlaces/ https://www.uniparconstrutora.com.br/tour/ https://solnascentealimentos.com.br/blog/ https://www.balinanny-babbyhire.com/faq/ https://adibintanpermata.com/shop/ slot4d totogacor Slot Gacor situs gacor 4D situs gacor slot4d SLOT4D slot4d slot gacor 4d Slot Thailand slot4d Slot Thailand Slot Thailand Slot Gacor Maxwin Slot Thailand Slot Thailand