Y
Y
Young_nigilist2021-03-13 20:40:49
JavaScript
Young_nigilist, 2021-03-13 20:40:49

How to compare MongoDB ObjectIDs?

I have an array of products:
604cf786c6395084135056.png
Each product has an _id, I also have a menu object that stores the id of the products:
604cf85611916425499822.png
I tried this way:

products.map(
      (product) =>
        product._id.toString() ===
        menu.products.map((menuProduct) => menuProduct.toString())
    )

But the result is always false. Instead of toString() I tried indexOf(), same thing.
How can I compare id to display a product?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question