Replicate only documents where {'public':true} in MongoDB -


i have following network/mongodb setup:

  • 1 primary mongodb database (10.0.0.1, not accessible internet) - contains private info in collection a, , collection b, documents created trusted user. @ point in time, user can mark document in collection b 'public', changes property {'public':false} {'public':true}.

  • 1 public mongodb database (10.0.0.2, runs webserver accessible internet via reverse proxy) - not contain collection a, should contain documents marked 'public' collection b. machine serve public documents users outside network.

how set mongodb when document in primary database (10.0.0.1) updated {'public':true}, gets replicated public mongodb database (10.0.0.2)?

other details:

  • i'm using php driver
  • the documents small, max 2kb
  • the load on these servers never exceed 10 concurrent users
  • eventual consistency ok, few minutes, i'd know options are.

so, reiterate, here's use case:

john vpns our private network, opens http://10.0.0.1/, creates document (call d2), marks private. john views older document, d1, , decides make public, clicking 'make public' button. server automagically makes document available on public server example.com (public ip x.y.z.w, internal ip 10.0.0.2).

john sends e-mail sarah , asks read document d1 (the 1 made public). sarah goes http://example.com , able read d1, never sees d2.

my goal achieve without having manually write scripts synchronize 2 databases. suspect should possible, can't figure out i've read mongodb replication.

i welcome advice.

thank you!

mongodb (as @ 2.0.6) not have support filtered replication.

however ... may possible implement own scheme update records based on tailable cursor of mongodb's oplog. local oplog.rs capped collection same mechanism used relay changes members of replica set , includes details inserts, deletes, , updates.

for example of technique, see blog post: creating triggers mongodb.

in case actions like:

  • copy record collection b if inserted or updated public:true
  • remove record collection b if deleted or updated in collection public:false

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -