import pymongoimport datetimefrom pymongo import Connection
con = Connection()
db=con['local']
oplog= db['oplog.rs']
newCol=db['newCol']
for doc in oplog.find({'ns':'hospital. patients'}):
if (doc['op']!='n'):
if(doc['op'] == 'u'):
key = doc['o2']['_id']
else:
key = doc['o']['_id']
if(key == 'ABCD'):
newCol.insert({'key':key, 'time':doc['ts'].as_datetime(), 'op_type':doc['op'],'Operation':str(doc['o'])})
i want to make the script tailable.
ie , when a record is added into the oplog, the scipt check the condition of namespace for that record only and if it satisfies then added into the newCol collection else discard . what i changes i have to make to script
thank you......
There is a project called mongo-connector which watches oplog in one
cluster to replay the operations on another.
Luckily, it's written in Python so you can look at the code there and
see how to do what you want to do.
https://github.com/10gen-labs/
https://github.com/10gen-labs/
See here for example of tailing the oplog in python:
Thank you sir for ur valuable info...
댓글 없음:
댓글 쓰기