Search code examples
mongodbmongodb-.net-drivermlab

How to modify string field in collection which resides in MongoLab


I have a collection in MongoLab called CollectionA.

In every document within this collectionA, i want to modify a field(say Field1 which is string) value from say "hello" to "hello world"

What is the most efficient way to do it and from where should i make this change(from a c# console app or mongoLab interface?)?


Solution

  • I would actually use the interactive mongo shell to do this. Connect to your mongolab database using the connection details shown in the web UI. Then, use an "update" command with a "$set" operator -- along the lines of the example at http://docs.mongodb.org/manual/reference/operator/set/

    For your example, it would be :

    db.collectionA.update( { Field1: "hello" }, { $set: { Field1: "hello world" } } );