0

Here's an example of what the objects look like in the database "activities":

Object{
   type{
      name : Leads
      category : Client Success
   }
}

and I want to change every activity where type -> name = leads to:

Object{
   type{
      name : Opportunity
      category : Client Success
   }
}

Here's what I've tried:

db.getCollection('activities').update(
// query 
{
    "type.name" : "Leads"
},

// update 
{
    "type.name" : "Opportunity Generated"
},

// options 
{
    "multi" : true, 
    "upsert" : false 
} );

Thanks for any help guys!

  • `db.getCollection('activities').update({ "type.name": "Leads" }, { "$set": { "type.name": "Opportunity Generated" } },{ "multi": true })`. Without the [`$set`](https://docs.mongodb.com/manual/reference/operator/update/set/), MongoDB interpets your request as meaning "replace" the current document with the content you provided. – Neil Lunn Jun 21 '17 at 23:55
  • Also see: [Add new field to a collection in MongoDB](https://stackoverflow.com/questions/7714216/add-new-field-to-a-collection-in-mongodb) – Neil Lunn Jun 21 '17 at 23:56

0 Answers0