如何在节点 Neo4j 中保存对象

How to keep objects in node Neo4j

我有具有这种结构的对象数组

[{
 name:'here is name, which can have  punctuation marks ',
 value: 'here will be text '
},
{
 name:'here is name, which can have  punctuation marks ',
 value: 'here will be text '
}]

我正在尝试找到将它保存在 neo4j 节点中的最佳方法。因为稍后我要搜索、过滤...我不想将孔对象保留为字符串。用名称 object.name 创建 属性 是不可能的,因为我有标点符号。理想的方法是将其保留为 属性,因为我打算将此数据用作节点的 属性,但从名称中删除标点符号也不是一种选择。 也许我可以把它们放在数组中

['here is the name', ' and the second element of array is the text']

在这种情况下,问题将是为具有此数组的 属性 提供正确的名称。 另一种选择是将所有数据保存在列表中,如下所示

tabs: ['first name - first value', ' second name - second value']

但要稍后进行搜索,我需要在列表中使用正则表达式。这似乎不灵活。 那么最好的方法是什么? 提前致谢!

在 Neo4j 数据库中存储对象的可能性很小。

  1. 您可以将您的 JSON 对象转换为字符串并将其保存为 属性 以后您可以使用 APOC procedures 进行对话 to/from(使用这些程序可以帮助您对这些进行过滤或排序)。
  2. 您可以创建辅助节点并将列表的每个元素视为一个单独的节点(我认为这是建议的方法)。

值得一提的是,您可以 link your nodes 保留订单,或者如果您真的不关心订单,则直接连接它们。

最简单的解决方案是使用 Andreas Kollegger

在 neo4j 社区论坛中提到的反引号
CREATE ({`here is "name", which has  punctuation marks!`:"here will be text"}) 

对于更复杂的情况Giuseppe Villani 建议更好的解决方案

CALL apoc.create.nodes(["MyLabel"], [{
 `name.with.dots`:'here is name, which can have  punctuation marks .',
 value: 'here will be text '
},
{
 name:'here is name, which can have  punctuation marks ',
 value: 'here will be text '
}]) yield node
return node 

创建一个带有标签的节点(在本例中为“MyLabel”),这样您就可以在特定标签中拥有您需要的所有数据(可能被索引 and/or 与其他实体连接)