2016-12-31 70 views
0

的所有節點添加/移除性質按照實施例的數據:暗號 - 跨越同一標籤


節點1:人{ID:1,名稱: '名稱一'}

節點2:人{ID :2,name:'NameTwo',年齡:42}

問題是:如果有可能標準化所有節點的標籤人名列表['id','name','age',' lastname'],以便將缺少的屬性添加到具有默認空值並僅使用密碼的節點中?

我一直在使用apoc.map.merge({first},{second}) yield value程序捆綁如下:

match (p:Person) 
call apoc.map.merge(proeprties(p),{id:'',name:'',age:'',lastname:''}) yield value 
return value 

但是我得到這個錯誤:

There is no procedure with the name apoc.map.merge registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.

雖然我可以確認我有APOC到位

bash-4.3# ls -al /var/lib/neo4j/plugins/apoc-3.1.0.3-all.jar 
-rw-r--r-- 1 root  root  1319762 Dec 14 02:19 /var/lib/neo4j/plugins/apoc-3.1.0.3-all 

和它顯示在apoc.help

neo4j-sh (?)$ call apoc.help("map.merge"); 
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| type  | name     | text                    | signature             | roles | writes | 
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| "function" | "apoc.map.merge"  | "apoc.map.merge(first,second) - merges two maps"         | "apoc.map.merge(first :: MAP?, second :: MAP?) :: (MAP?)" | <null> | <null> | 
| "function" | "apoc.map.mergeList" | "apoc.map.mergeList([{maps}]) yield value - merges all maps in the list into one" | "apoc.map.mergeList(maps :: LIST? OF MAP?) :: (MAP?)"  | <null> | <null> | 
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
2 rows 
47 ms 

回答

1

請注意,現在這些功能都是現在的功能,因此您不需要使用CALL或YIELD等程序調用它們。這應該工作:

match (p:Person) 
RETURN apoc.map.merge(properties(p),{id:'',name:'',age:'',lastname:''}) 

請記住,這個查詢只會影響是什麼回來了,因爲你沒有使用要更新的節點屬性。

可以使用+=運營商更新節點的屬性,而不是使用apoc.map.merge:

match (p:Person) 
set p += {id:'',name:'',age:'',lastname:''} 

請記住,這都和apoc.map.merge將取代現有值,所以你會爲所有人填寫id,姓名,年齡和姓氏。

目前我不認爲Neo4j或APOC中有功能可以在保留現有屬性而不是替換的同時在屬性中進行合併。也就是說,您可能會使用一些解決方法。

COALESCE()是一個有用的函數,因爲它允許您在缺省值爲空的情況下提供默認值。如果屬性是空的人,用附帶的空字符串作爲默認:

例如,您可以使用此更新所有屬性

match (p:Person) 
with {id:COALESCE(p.id, ''), name:COALESCE(p.name, ''), age:COALESCE(p.age, ''), 
    lastname:COALESCE(p.lastname, '')} as newProps 
set p += newProps