Import contributions to neo4j

This commit is contained in:
Robert Schäfer 2019-01-18 23:53:00 +01:00
parent 97e6acf46b
commit 887a6d201f
3 changed files with 24 additions and 20 deletions

View File

@ -0,0 +1,23 @@
CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post
MERGE (p:Post {id: post._id["$oid"]})
ON CREATE SET
p.title = post.title,
p.slug = post.slug,
p.image = post.teaserImg,
p.content = post.content,
p.contentExcerpt = post.contentExcerpt,
p.visibility = toLower(post.visibility),
p.createdAt = post.createdAt.`$date`,
p.updatedAt = post.updatedAt.`$date`,
p.deleted = post.deleted,
p.disabled = NOT post.isEnabled
WITH p, post, post.tags AS tags, post.categoryIds as categoryIds
UNWIND tags AS tag
UNWIND categoryIds AS categoryId
MATCH (c:Category {id: categoryId}),
(u:User {id: post.userId})
MERGE (t:Tag {id: apoc.create.uuid(), name: tag})
MERGE (p)-[:TAGGED]->(t)
MERGE (u)-[:WROTE]->(p)
MERGE (p)-[:CATEGORIZED]->(c)
;

View File

@ -13,25 +13,6 @@ ON CREATE SET b.key = badge.key,
b.status = badge.status b.status = badge.status
CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post
MERGE (p:Post {id: post._id["$oid"]})
ON CREATE SET p.title = post.title,
p.slug = post.slug,
p.image = post.teaserImg,
p.content = post.content,
p.contentExcerpt = post.contentExcerpt,
p.visibility = apoc.text.toUpperCase(post.visibility),
p.createdAt = datetime(post.createdAt["$date"]),
p.updatedAt = datetime(post.updatedAt["$date"])
WITH p, post, post.tags AS tags, post.categoryIds as categoryIds
UNWIND tags AS tag
UNWIND categoryIds AS categoryId
MATCH (c:Category {id: categoryId}),
(u:User {id: post.userId})
MERGE (t:Tag {id: apoc.create.uuid(), name: tag})
MERGE (p)-[:TAGGED]->(t)
MERGE (u)-[:WROTE]->(p)
MERGE (p)-[:CATEGORIZED]->(c)
CALL apoc.load.json('file:/mongo-export/comments.json') YIELD value as comment CALL apoc.load.json('file:/mongo-export/comments.json') YIELD value as comment

View File

@ -11,7 +11,7 @@ u.wasInvited = user.wasInvited,
u.role = toLower(user.role), u.role = toLower(user.role),
u.createdAt = user.createdAt.`$date`, u.createdAt = user.createdAt.`$date`,
u.updatedAt = user.updatedAt.`$date`, u.updatedAt = user.updatedAt.`$date`,
u.deleted = false, u.deleted = user.deletedAt IS NOT NULL,
u.disabled = false u.disabled = false
WITH u, user, user.badgeIds AS badgeIds WITH u, user, user.badgeIds AS badgeIds
UNWIND badgeIds AS badgeId UNWIND badgeIds AS badgeId