Neo4j BatchInserter使用setNodeProperties设置带有值的数组(Neo4j BatchInserter using setNodeProperties to set an

编程入门 行业动态 更新时间:2024-10-09 06:23:58
Neo4j BatchInserter使用setNodeProperties设置带有值的数组(Neo4j BatchInserter using setNodeProperties to set an array with values)

我正在使用BatchInserter实例来获取和设置节点的属性。 我的数据在某些属性中有多个值。

property value ======== ========= synonym animal synonym mammalian

我想将这些值放在同一节点的同一属性中。

我使用以下代码片段来读取和设置值:

String[] values = {"animal", "mammalian"}; for (int i = 0; i < values.length(); i++) { Map<String, Object> nodeProps = db.getNodeProperties(0); // Node 0 properties nodeProps.put("synonym", values[i]); db.setNodeProperties(0, nodeProps); }

在第一次迭代属性中, synonym获得值animal 。 在第二次迭代中,属性 mammalian值覆盖

我的问题是:如何获取之前的值,添加新的值并将属性设置为节点,以便我可以在图形中获得synonym=['animal', 'mammalian'] ?

I am using the BatchInserter instance to get and set properties for nodes. My data have multiple values in some properties.

property value ======== ========= synonym animal synonym mammalian

I want to put this values, in the same property in the same node.

I have used the following code snippet to read and set values:

String[] values = {"animal", "mammalian"}; for (int i = 0; i < values.length(); i++) { Map<String, Object> nodeProps = db.getNodeProperties(0); // Node 0 properties nodeProps.put("synonym", values[i]); db.setNodeProperties(0, nodeProps); }

In the first iteration property synonym gets value animal. In the second iteration, the property is overridden by the value mammalian.

My question is: How can I get the previous value(s), add the new one and set the property to the node so I can get synonym=['animal', 'mammalian'] in graph?

最满意答案

如果要在节点/关系属性上具有多个值,则需要使用数组。 所以你在属性synonyms有一个String[]作为值:

修改现有财产:

String[] values = {"animal", "mammalian"}; Map<String, Object> nodeProps = db.getNodeProperties(0); String[] existingValues = nodeProps.get("synonym"); // using org.apache.commons.lang.ArrayUtils from Apache Commons Lang: String[] amendedValues = ArrayUtils.addAll(existingValues, values); nodeProps.put("synonym", amendedValues); db.setNodeProperties(0, nodeProps);

If you want to have multiple values on a node/relationship property you need to use arrays. So you have on property synonyms with a String[] as value:

To amend an existing property:

String[] values = {"animal", "mammalian"}; Map<String, Object> nodeProps = db.getNodeProperties(0); String[] existingValues = nodeProps.get("synonym"); // using org.apache.commons.lang.ArrayUtils from Apache Commons Lang: String[] amendedValues = ArrayUtils.addAll(existingValues, values); nodeProps.put("synonym", amendedValues); db.setNodeProperties(0, nodeProps);

更多推荐

本文发布于:2023-08-03 22:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   setNodeProperties   BatchInserter   Neo4j   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!