1

I am currently trying to build a swap query for my database, i currently have the following: db.customers.findOneAndUpdate( { name }, { currentCustomer: swapCustomerId, $push: { que: currentCustomerId }, $pull:{ que : swapCustomerId } }, { new: true })

Executing this query gives me the following error : Cannot update 'que' and 'que' at the same time.

I have read about Bulk writes, but i cant find a way to access a specific document to edit with it ?

Any ideas on how to solve this would be greatly appreciated.

duck
  • 1,674
  • 2
  • 16
  • 26

1 Answers1

2

This is a MongoDB restriction in which you cannot perform two sets of operations on the same key:value pair. You can have them in separate atomic operations,ergo your going to have to perform them individually with two separate queries.

Refer to this : Pull and addtoset at the same time with mongo

Community
  • 1
  • 1