当您提供构建图的遍历时会很有帮助,因此我们可以为您提供经过测试的答案。
g.addV('Organization').property(id, 'Org-1').as('org1').
addV('social_account').property(id, 'Twitter-01').property('social', 'Twitter').property('updated_at', 1234).as('twitter01').
addE('has_social_account').from('org1').to('twitter01').
addV('social_account').property(id, 'Medium-34').property('social', 'Medium').property('updated_at', 1345).as('medium34').
addE('has_social_account').from('org1').to('medium34').
addV('social_account').property(id, 'Insta-55').property('social', 'Instagram').property('updated_at', 4567).as('insta55').
addE('has_social_account').from('org1').to('insta55').
addV('Organization').property(id, 'Org-2').as('org2').
addV('social_account').property(id, 'Twitter-39').property('social', 'Twitter').property('updated_at', 1111).as('twitter39').
addE('has_social_account').from('org2').to('twitter39').
addV('social_account').property(id, 'Twitter-60').property('social', 'Twitter').property('updated_at', 2345).as('twitter60').
addE('has_social_account').from('org2').to('twitter60').
addV('social_account').property(id, 'Insta-19').property('social', 'Instagram').property('updated_at', 4567).as('insta19').
addE('has_social_account').from('org2').to('insta19')
这里是遍历拥有多个 Twitter 帐户的组织以及需要删除的 Twitter 帐户的 ID。
g.V().hasLabel('Organization').where(out('has_social_account').has('social', 'Twitter').count().is(gt(1))).
project('org', 'to_drop').
by(id).
by(out('has_social_account').has('social', 'Twitter').
order().by('updated_at', desc).
range(1, -1).id().fold())
where 步骤按拥有多个 Twitter 帐户的组织过滤。而project 步骤获取这些组织的 ID 及其需要删除的 Twitter 帐户。
为了获取需要删除的 Twitter 帐户,第二个 by 调制器中的嵌套遍历获取与组织关联的 Twitter 帐户,并根据“updated_at”的值(降序)对它们进行排序。然后使用range步骤跳过第一个不需要删除的推特账号。