title: MongoDB C# driver: create document if not exists
body: <p>I have some POCO of a type <code>User</code> and I have some concerns its properties going to change in future. I have a mongodb with <code>Users</code> collection to store the data. There's no uniqueness constraint on it, and I can't create one unfortunatelly. My app imports a bunch of old users from 3rd party archive source and I want to be able to write these users into mongo, but I don't want the duplicates and I don't want to replace user data on match because data in mongo is actual. Basically we can define user duplicate by matching filter like <code>a.Username == b.Username &amp;&amp; a.Email == b.Email</code> or something similar, I don't want it to be relevant to this question, let's just say there's a way we can tell if users A and B are the same.</p>
  
  <p>So it seems like my only option here is using upsert Update with SetOnInsert. In C# driver there's a method <code>Builders&lt;User&gt;.Update.SetOnInsert&lt;TField&gt;(Expression&lt;User,TField&gt;, TField)</code> but I will have to call it multiple times to enumerate all the properties. If these properties going to change in future, someone will have to update this method and I don't like it.</p>
  
  <p>Is there a way to bypass this problem? Maybe by using reflecion and <code>PropertyInfo</code> or by working with <code>BsonDocument</code> directly? Or maybe I missing somethign and there's an easier way to do it? Thanks in advance.</p>