mongodb中的选择性复制 [英] Selective replication in mongodb

查看:104
本文介绍了mongodb中的选择性复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个运行在通过局域网连接的不同服务器上的两个MongoDB.我想将记录从服务器1的几个集合复制到服务器2的集合.有什么方法可以做到.下面是我要实现的目标的图形表示.

I have two MongoDB running in two different servers connected via LAN. I want to replicate records from few collections from server 1 to collections in server 2. Is there any way to do it. Below is the pictorial representation of what I want to achieve.

以下是我考虑使用的方法.

Following are the methods I consider using.

  1. MongoDB复制-但它会复制所有集合.可以在MongoDB中进行选择性复制吗?
  2. Oplog观察程序API-请提出一些可靠的Java API

还有其他方法吗?最好的方法是什么?

Is there any other way to do this ? and what is the best way of doing it ?

推荐答案

MongoDB尚不支持选择性复制,这听起来好像您实际上并没有在寻找选择性复制,但更多地是为了选择性复制,因为复制可以确保使用该复制的某些规则.服务器.

MongoDB does not yet support selective replication and it sounds as though you are not actually looking for selective replication but more for selective copying since replication ensures certain rules of using that server.

我不确定您是什么意思的oplog观察程序API,但是只要查询一下,就可以很容易地随时间读取oplog:

I am not sure what you mean by a oplog watcher API but it is easy enough to read the oplog over time by just querying it:

> use local
> db.oplog.rs.find()

( http://docs.mongodb.org/manual/reference/local-数据库/)

,然后在制作的脚本中存储已复制记录的最新时间戳.

and then storing the latest timestamp of the record you have copied within a script you make.

您还可以在操作日志上的此处使用尾部光标,以有效地监听(发布/订阅)更改并将其复制到其他服务器上.

You can also use a tailable cursor here on the oplog to effectiely listen (pub/sub) to changes and copy them over to your other server.

这篇关于mongodb中的选择性复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆