#Cannot use filter in updateOne sdk

5 messages · Page 1 of 1 (latest)

hybrid niche
#

I have used this filter to check data before update but it doesn't work. How can i solve this problem.

And how can i get result if it cannot update data because condition is wrong ?

My code:

`const result = await inventoryCollection.updateOne(
  inventory.id,
  {
    available_stock: inventory.available_stock - orderItem.quantity,
  },
  {
    filter: {
      available_stock: {
        _eq: 0,
      },
    },
    fields: ['available_stock'],
  },
);`
arctic zenithBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

grizzled locust
#

filter or other query options in an update api call only affects the returned value. The update will be done either way. You'll need to check your condition either before updating or in validation

hybrid niche
#

How can i check and update in the one transaction. Because i would like to use for reserver stock

#

If i use mutation can i check condition before update