Announcement Announcement Module
Collapse
No announcement yet.
MongoDB update query for removing some elements from an array field Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB update query for removing some elements from an array field

    Hi,
    I have this MongoDB document:

    Code:
    {
        "name" : "Joe",
        "exams" : [
            {
               "foo" : "bar",
               "exam" : 1
            },
            {
               "foo" : "bar",
               "exam" : 2
            },
            {
               "foo" : "bar",
               "exam" : 3
            }
        ]
    }
    
    {
        "name" : "Peter",
        "exams" : [
            {
               "foo" : "bar",
               "exam" : 2
            },
            {
               "foo" : "bar",
               "exam" : 3
            },
            {
               "foo" : "bar",
               "exam" : 4
            }
        ]
    }
    And I have this update query that removes som elements from the exams field:

    Code:
    db.students.update({"exams.exam": {$in: [2,3]}}, {$pull: {exams: {exam: {$in:[2, 3]}}}}, {multi: true})
    Can someone please tell me how to write a Query with the, awsam ,spring-mongodb query API?
Working...
X