1

I have a likes array embed in photos collection. Likes array contains user_id, Every time the user presses the like button, I need to check if the user_id exists in the like array. If it doesn't exist, I push user_id to likes array, else I pull it out of likes array. So I need to perform two queries. I want to encapsulate them in a single query.

Photos:

"likes" : [ 
        {
            "user_id" : ObjectId("")
        }, 
        {
            "user_id" : ObjectId("")
        }
],
3
  • Conditional updates are supported only after MongoDB v4.2. Which version are you using? Commented Sep 8, 2019 at 9:09
  • @Mr.S.Sharma I use MongoDB version v4.0.12, Ubuntu 18.04 LTS. Commented Sep 8, 2019 at 10:21
  • Two different operations on the same array cannot be performed in v4.0.12. Commented Sep 8, 2019 at 12:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.