Deefa Deefa -4 years ago 144
C# Question

Insert a new field into an existing collection (many documents) in MOngo using C# driver

How can I insert a new field into a MongoCollection using the C# Update api.

What Im trying to do is, I have a HomePhoneId field that I need to insert in every document of the People collection in MOngo.

Please has anyone done this before in C#?
Any ideas?

Thanks.

Answer Source

Following code should work:

collection.Update(Query.Null, Update.Set("HomePhoneId", "some value"), UpdateFlags.Multi)

Btw, here is you can look into driver documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download