Commit 7ab19445 authored by Pavel Kuzmenko's avatar Pavel Kuzmenko
Browse files

Merge branch 'alesh/43/refactor-mirror-update' into 'master'

refactor: fix mirror issue on client update

See merge request !173
parents 9d7b04e6 f1f1b08c
......@@ -89,7 +89,7 @@ class MongoDBMirror:
op = entry['op']
data = entry['o']
ts = [entry['ts'].time, entry['ts'].inc]
collection = client.namespace.split('.')[-1]
db, collection = client.namespace.split('.')
try:
if op == MongoOperation.NOOP and not entry['ns']:
data = self._serialize_data(data)
......@@ -101,16 +101,14 @@ class MongoDBMirror:
await client.upsert(ts, data)
elif op == MongoOperation.UPDATE:
if '$v' in data:
if _set := data.get('$set'):
data['$set'] = self._serialize_data(_set)
if _unset := data.get('$unset'):
data['$unset'] = self._serialize_data(_unset)
data.update(entry['o2'])
data = self._serialize_data(data)
await client.update(ts, data)
else:
data = self._serialize_document(data, collection)
await client.upsert(ts, data)
data = await self._mongo[db][collection].find_one(
entry['o2'], sort=[('dateModified', 1)]
)
if data is None:
LOG.warning(f'Document not found: {collection} with {entry["o2"]["_id"]}')
continue
data = self._serialize_document(data, collection)
await client.upsert(ts, data)
elif op == MongoOperation.DELETE:
data = self._serialize_data(data)
await client.delete(ts, data)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment