Delete documents that satisfies multiple conditions MongoDB

Viewed 17

I'm in the mongo shell and I have to remove documents that satisfies all of these conditions together:

status: 'CO'
renewPlan: true
paymentType: 'credit_card'
gatewayPayment: 'ebanx'

Ive tried this but didnt work:

db.transactions.deleteMany({ status : "CO" } $and {renewPlan: true } $and {paymentType: 'credit_card'} $and {gatewayPayment: 'ebanx'})
1 Answers

MongoDB will implicitly and the conditions if you specify them all in one filter document. So you can do:

db.transactions.deleteMany({
  status: "CO",
  renewPlan: true ,
  paymentType: 'credit_card',
  gatewayPayment: 'ebanx'
})
Related