2

Test Data:-

professor:{
 name:"temp1",
 department:[
 {name:"pro1",
 review:[
 {paper:"paper1",status:"review",paperid:"1"}
 ]}]}

I want to update the status "review" to "finish". For to search I use :

 {
department: {
                $elemMatch: {
                  review: {
                    $elemMatch: {
                      paperid: id
                    }
                  }
                }
          }}

2 Answers 2

1

If you want to update all your documents where the status is review use:

db.collection.update(
  {},
  {$set: {"professor.department.$[].review.$[r].status": "finish"}},
  {arrayFilters: [{"r.status": "review"}]}
)

See how it works on the playground example

If you want to update only where the department.name is pro1 use:

db.collection.update(
  {},
  {$set: {"professor.department.$[d].review.$[r].status": "finish"}},
  {arrayFilters: [{"d.name": "pro1"}, {"r.status": "review"}]}
)

See how it works on the playground example - department

Sign up to request clarification or add additional context in comments.

Comments

0

by specify paperid

db.collection.updateOne(
    {},
    {
        $set: { "professor.department.$[].review.$[r].status": 'finish' }
    },
    {
        arrayFilters: [{ "r.paperid": '1' }]
    }
)

Comments

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.