0

I would like to run an update command to mongodb that will update all the info inside of an collection. in mysql i will just do :

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

How can I achive this in mongodb? so far this is what I have :

db.property.update(
   {
      $set: {"image":{"isHosted": false, "imageUrl": "", "imageMediumUrl": "", "imageThumbUrl": ""}}
   }
)

This is what my current property looks:

{
   "_id": ObjectId("54183b8ee8643951f6b3ee0f"),
   "image": "http: \/\/img.com\/California\/Properties\/JPG_Main\/341\/3513341.jpg",
}

Thanks in advance, hope someone can help me as a newbie with mongodb

1 Answer 1

1

You're missing a clause to your set statement. You need the equivalent of the where clause.

IE:

 db.property.update( { image: "http:\/\/img.com\/California\/Properties\/JPG_Main\/341\/3513341.jpg"},
   {
      $set: {"image":{"isHosted": false, "imageUrl": "", "imageMediumUrl": "", "imageThumbUrl": ""}}
   }
)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the reply betsey, how about if I want to target all data? that's why I did not add the { image: "http:\/\/img.com\/California\/Properties\/JPG_Main\/341\/3513341.jpg"},
Just leave the first argument of update empty {}. This is an empty query clause which matches all documents.

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.