Search for registration in Mongo and update

Asked

Viewed 60 times

1

I need some help to make a update in a specific record. Below is the document I want to change.

{  
  "_id":"ddc07497-003d-3dff-8f82-24b9b980a568",
  "date":"2018-04-19T17:14:29.699Z",
  "messages":[  
     {  
        "intents":[  

        ],
        "entities":[  

        ],
        "input":{  
           "text":"attachments",
           "date":"2018-04-19T17:14:44.699Z",
           "user":{  

           },
           "payload":{  
              "watsonOnly":"attachments"
           },
           "files":[  
              {  
                 "name":"Screen Shot 2018-04-05 at 09.00.15.png",
                 "url":"http://localhost:3000//uploads/5a8704792db4cf0a896ca668/files/35bd963d-4477-4817-8d29-3b234202978a.png"
              }
           ]
        },
        "output":{  
           "text":[  
              "Você pode reformular sua afirmação? Eu não estou entendendo."
           ],
           "nodes_visited":[  
              "Em outros casos"
           ],
           "log_messages":[  

           ],
           "date":"2018-04-19T17:14:45.125Z",
           "user":{  
              "id":"a079d4be-5190-ebe6-c55f-623aab50a665",
              "name":"Robo do xande",
              "avatar":"http://localhost:3000/uploads/5a8704792db4cf0a896ca668/avatar/e332048b-e7dd-45be-a6df-59b4a57545f8.jpeg"
           }
        }
     }
  ],
  "sizeOfmessages":2}

I need to find the document with the same _id and then the same url that is inside input.files, and when finding, update and set the url as empty.

Could someone help me?

  • Hello! What have you tried?

  • 2

    $match: { 
 "_id":params._id, 
 $or: [{"messages.input.files.url": params.url},{messages.output.files.url": params.url }] 
 },
 {
 $set: { 
 "messages.0.input.$.files.url": "",
 "messages.0.output.$.files.url": "",
 }
 }
 });

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.