fal hmed
fal hmed

Reputation: 57

Problem when syncing data from mongodb to neo4j with mongo connector

I'm using mongodb and neo4j and syncing data with mongo connector and neo4j doc manager . When starting mongo-connector all is working fine, all my document in mongodb have been synchronised very well to neo4j with all the specific fields that i want, but when updating any document in mongodb there is a problem .All the fields of the node(that refer to that document) in neo4j are deleted and there is just id field of neo4j and email field.

I'm using debuging mode with mongo connector and i found that pyneo (when updating document in mongo) delete the node and then create another node with only email field. I'm using python 3.6.7

this is what mongo connector log look like when i change something in a document py2neo is deleting the node and then create another with only the email field :

 2019-04-16 16:40:02,428 [DEBUG] mongo_connector.oplog_manager:271 
    - OplogThread: Operation for this entry is u
    2019-04-16 16:40:02,428 [INFO] py2neo.cypher:200 - begin
    2019-04-16 16:40:02,428 [INFO] py2neo.cypher:266 - append 'MATCH 
    (d:Document:`user_trustem`) WHERE d._id={doc_id} OPTIONAL MATCH 
    (d)-[r]-(c) DELETE r WITH d, c OPTIONAL MATCH (c)-[s]-() WITH 
    d,c,s, CASE WHEN s IS NULL THEN c ELSE NULL END AS n DELETE n' 
    {'doc_id': '5ca6043820f3b02227f2245a'}
    2019-04-16 16:40:02,428 [INFO] py2neo.cypher:266 - append 'MATCH [z][1](d:Document:`user_trustem`) WHERE d._id={doc_id} SET d={set_parameter}' {'doc_id': '5ca6043820f3b02227f2245a', 'set_parameter': {'email': '[email protected]'}}
2019-04-16 16:40:02,429 [INFO] py2neo.cypher:266 - append 'MATCH (d:Document:`user_trustem`) WHERE d._id={doc_id} SET d={set_parameter}' {'doc_id': '5ca6043820f3b02227f2245a', 'set_parameter': {'email': '[email protected]'}}
2019-04-16 16:40:02,429 [INFO] py2neo.cypher:331 - commit

before updating after updating

Upvotes: 0

Views: 275

Answers (1)

cybersam
cybersam

Reputation: 67019

The SET n = $map syntax (or the deprecated syntax, SET n = {map}) will basically delete all existing properties in n and replace them with the properties in the map parameter.

To merely add/update properties in n without deleting any properties, you need to use the SET n += $map syntax.


By the way, this snippet:

WITH d, c
OPTIONAL MATCH (c)-[s]-()
WITH d,c,s, CASE WHEN s IS NULL THEN c ELSE NULL END AS n
DELETE n

could be done this way, which is not only a bit easier to read but faster (since this snippet just tests that there are no relationships -- without wasting the effort to get all the ones that happen to exist):

FOREACH(x IN CASE WHEN NOT (c)--() THEN [c] END | DELETE x)

Upvotes: 0

Related Questions