title: Synchronize mongo databases on different servers
body: <p>I have next situation. I have two mongodb instances on different servers. 
  For example</p>
  
  <pre><code>Mongodb instance on server "one" (host1:27017) with database: "test1"
  Mongodb instance on server "two" (host2:27017) with database: "test2"
  </code></pre>
  
  <blockquote>
    <p>Now, i need to synchronize "test1" database from "host1:27017" with
    "test2" from "host2:27017".</p>
  </blockquote>
  
  <p>By "synchronize" I mean next:</p>
  
  <ol>
  <li><p>If some collection from "test1" database doesn't exist in "test2" then this collection should be full copied in "test1" database.</p></li>
  <li><p>If some record from collection doesn't exist in "test2" database, then must be added otherwise updated. If record not exist in A collection in "test1" database, but exist in A collection in "test2" database, then record must be deleted from "test2". </p></li>
  </ol>
  
  <p>By the way here is problem. For example:
  "test1" database has collection "A" with the following documents:</p>
  
  <pre><code>{
   _id: "1",
   name: "some name"
  }
  </code></pre>
  
  <p>"test2" database has collection "A" with the following documents:</p>
  
  <pre><code>{
   _id: "1",
   name: "some name"
  }
  
  {
   _id: "2",
   name: "some name2"
  }
  </code></pre>
  
  <p>If I perform db.copyDatabase('test1', 'test2', "host2:27017") I get error:</p>
  
  <blockquote>
    <p>"errmsg" : "exception: E11000 duplicate key error index: test1.A.$<em>id</em>  dup key: { : \"1\" }"</p>
  </blockquote>
  
  <p>Same with <code>cloneDatabase</code> command. How I can resolve it ?</p>
  
  <p>In general what are the ways to synchronize databases? 
  I know what the simplest way is just copy files from one server to second, but maybe there are better ways.</p>
  
  <p>Please help. I'm newcomer in mongo. Thanks. </p>