-1

I working on NodeJS and MongoDB and I have database JSON like this

{
   _id: "123"
   classroom: [
    {
      classId: "2046"
      className: "10b"
    },
    {
      classId: "2079"
      className: "12b"
    }   
  ]
},

{
   _id: "456"
   classroom: [
    {
      classId: "2069"
      className: "36b"
    },
    {
      classId: "2011"
      className: "36c"
    }   
  ]
}

I want to delete classroom on

_id: "123" and have classId: "2046"

,so after delete process, I will have JSON like this

   {
       _id: "123"
       classroom: [
        {
          classId: "2079"
          className: "12b"
        }   
      ]
    },

    {
       _id: "456"
       classroom: [
        {
          classId: "2069"
          className: "36b"
        },
        {
          classId: "2011"
          className: "36c"
        }   
      ]
    }

So please help me to do that, any advices are very welcome thank you

1

1 Answer 1

0

You can use this query to do that :

db.collection.update({
    _id: '123'
}, {
    $pull: {
        classroom: {
            classId: '2046'
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.