我需要创建一个List,然后添加一个包含大量数据的关系。因此,我试图使用apoc.periodic.iterate,如下所示:
CREATE (pl:List {id: 'some-random-id-01', title:'title-01'})
WITH pl as pl
CALL apoc.periodic.iterate('
MATCH (p:DbLists)
WHERE p.name CONTAINS "name"
RETURN p.id as Ids
SKIP 0 LIMIT 10000
', '
WITH {pl} as pl
UNWIND Ids as Id
MATCH (p:DbInfos {id: Id})
WITH p as cn
SET cn :Contacts
WITH cn as cn
MERGE (pl)-[cnpt:CONTACTS_LISTING { email: cn.email } ]->(cn)
RETURN pl
',
{ batchSize:100, parallel:true, pl:pl }
) YIELD batches
return pl, batches在上面的查询中,首先创建一个List,然后从DbLists中查找DbLists.name CONTAINS "name-01"和返回 id的DbLists数据。现在,使用CREATE of DbLists与DbInfos建立关系。
最后返回pl, batches。
我的输出是pl和100的batches值。但是,当我探索我的数据库时,我只找到了List数据,而没有找到任何其他数据,比如Contacts, CONTACTS_LISTING(relationship)等等。
样本数据:
DbLists::
[{
id: 'some-id-01',
name: 'some name 01',
email: 'email1@gmail.com'
}, {
id: 'some-id-02',
name: 'some name 02',
email: 'email2@gmail.com'
},{
id: 'some-id-03',
name: 'some name 03',
email: 'email3@gmail.com'
},{
id: 'some-id-04',
name: 'some namex 04',
email: 'email4@gmail.com'
},
......................
.........................
]DbInfos::
[
{
id: 'list-id-01',
name: 'some name 01',
email: 'email1@gmail.com'
}, {
id: 'list-id-02',
name: 'some name 02',
email: 'email2@gmail.com'
},{
id: 'list-id-03',
name: 'some name 03',
email: 'email3@gmail.com'
},{
id: 'list-id-04',
name: 'some name 04',
email: 'email4@gmail.com'
}
]期望的结果::
List { {id: 'some-random-id-01', title:'title-01'} }
/ \
/ \
C_L {eml1} C_L {eml2}
/ \
DbInfos::Contacts DbInfos::Contacts {}
{ id: 'list-id-01', { id: 'list-id-02',
email: 'email1@gmail.com' email: 'email2@gmail.com'}
}
....................................
....................................在此:
C_L = CONTACTS_LISTING
eml1 = 'email1@gmail.com'
eml2 = 'email2@gmail.com'在这里,DbInfos和DbLists有相同的标签。
有什么建议吗?
提前谢谢。
发布于 2018-03-27 11:24:41
我看到了可能的问题,因为您没有在下面传递变量pl,并且在没有确保cn.email属性存在的情况下创建一个关系:
...
WITH cn as cn
MERGE (pl)-[cnpt:CONTACTS_LISTING { email: cn.email } ]->(cn)
...尝试将内部语句更改为:
WITH {pl} as pl
UNWIND {Ids} as Id
MATCH (cn:DbInfos {id: Id}) SET cn :Contacts
MERGE (pl)-[cnpt:CONTACTS_LISTING]->(cn) SET cnpt.email = cn.email
RETURN pl发布于 2018-03-27 14:27:10
首先,UNWIND Ids as Id MATCH (p:DbInfos {id: Id})是不正确的,因为在DbInfo和DbLists中有绝对不同的in。因此,您将永远不会在p:DbInfo中找到具有{id: Id}的节点。
我已经更正了你的查询并进行了测试。所以这必须有效。
CREATE (pl:List {id: 'some-random-id-01', title:'title-01'})CALL apoc.periodic.iterate(' MATCH (p:DbLists) WHERE p.name CONTAINS "name" RETURN collect(p.id) as Ids SKIP 0 LIMIT 10000 ', ' MATCH (pl:List {id: \'some-random-id-01\', title:\'title-01\'}) WITH pl as pl UNWIND {Ids} as Id MATCH (p:DbInfos {id: Id}) SET p:Contacts WITH p,pl MERGE (pl)-[cnpt:CONTACTS_LISTING { email: p.email } ]->(p) RETURN pl ', { batchSize:100, parallel:true} ) YIELD batches MATCH p=()-[r:CONTACTS_LISTING]->() RETURN p
如果你有什么问题的话,不客气!
https://stackoverflow.com/questions/49509769
复制相似问题