Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

mongodb

How can I insert a new field into a MongoDB collection using the C# Update API?

What I am trying to do: I have a HomePhoneId field that I need to insert into every document in my People collection.

Any ideas?

like image 479
Deefa Avatar asked Jun 04 '12 08:06

Deefa


1 Answers

Following code should work:

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

Btw, here is you can look into driver documentation.

like image 193
Andrew Orsich Avatar answered Nov 12 '22 16:11

Andrew Orsich