mongodb - Synchronize mongo databases on different servers -


i have next situation. have 2 mongodb instances on different servers. example

mongodb instance on server "one" (host1:27017) database: "test1" mongodb instance on server "two" (host2:27017) database: "test2" 

now, need synchronize "test1" database "host1:27017" "test2" "host2:27017".

under "synchronize" mean next:

  1. if collection "test1" database doesn't exist in "test2" collection should full copied in "test1" database.

  2. if record collection doesn't exist in "test2" database, must added otherwise updated. if record not exist in collection in "test1" database, exist in collection in "test2" database, record must deleted "test2".

by way here problem. example: "test1" database has collection "a" next documents:

{  _id: "1",  name: "some name" } 

"test2" database has collection "a" next documents:

{  _id: "1",  name: "some name" }  {  _id: "2",  name: "some name2" } 

if perform db.copydatabase('test1', 'test2', "host2:27017") error: "errmsg" : "exception: e11000 duplicate key error index: test1.a.$_id_ dup key: { : \"1\" }"

same clonedatabase command. how can resolve ?

in general ways synchronize databases? know simplest way copy files 1 server second, maybe there better ways.

please help. i'm newcomer in mongo. thanks.

i haven't tried this, current mongodb documents describe replication set equivalent master-slave replication:

deploy master-slave equivalent using replica sets

if want replication configuration resembles master-slave replication, using replica sets, consider following replica configuration document. in deployment hosts , 1 provide replication equivalent two-instance master-slave deployment:

{    _id : 'setname',    members : [               { _id : 0, host : "<master>", priority : 1 },               { _id : 1, host : "<slave>", priority : 0, votes : 0 }   ] } 

see replica set configuration more information replica set configurations.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -