这个cypher 为啥 运行 报错
UNWIND {[{“nodeId”:“ec4ce2ce-2626-11ea-ad00-0242ac1e4105”}]} AS nodeMap MATCH (n) WHERE n.id = nodeMap.nodeId SET n.knwlgId= ‘1912271750370000181’, n.knwlgName= ‘星期五02’ return n
7 回复
试试修改成这样
UNWIND [{nodeId:“ec4ce2ce-2626-11ea-ad00-0242ac1e4105”}] AS nodeMap MATCH (n) WHERE n.id = nodeMap.nodeId SET n.knwlgId= “1912271750370000181”, n.knwlgName= “星期五02” return n
如果是想在程序里把map数组转string,然后拼在UNWIND 里面的话,我这样尝试了一下,可以用,虽然比较粗糙
//大概意思就是 遍历map数组的key,替换掉字符串
//例如{"nodeId":"ec4ce2ce-2626-11ea-ad00-0242ac1e4105"} -> {nodeId:"ec4ce2ce-2626-11ea-ad00-0242ac1e4105"}
func ReplaceKeyMap(targetString string) string {
fieldNameMap := TestStruct(Article{})
if fieldNameMap == nil {
fmt.Println("空结构体,无数据替换")
return ""
}
for _, entity := range fieldNameMap {
targetString = strings.Replace(targetString, "\""+entity+"\"", entity, -1)
}
return targetString
}
尝试用JAVA 写了一下
public static void ReplaceKeyMap() {
//生成测试数据
ArrayList<HashMap<String, String>> mapList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < 5; i++) {
HashMap<String, String> nodeMap = new HashMap<String, String>();
nodeMap.put("nodeId", "ec4ce2ce-2626-11ea-" + i);
mapList.add(nodeMap);
}
String mapString = JsonUtil.toJsonString(mapList);
System.out.println(mapString);
Map<String, String> nodeMap = new HashMap<String, String>();
nodeMap.put("nodeId", "ec4ce2ce-2626-11ea");
//核心地方
for (Map.Entry<String, String> stringStringEntry : nodeMap.entrySet()) {
mapString = mapString != null ? mapString.replaceAll("\"" + stringStringEntry.getKey()
+ "\"", stringStringEntry.getKey()) : "";
}
System.out.println(mapString);
}
[{"nodeId":"ec4ce2ce-2626-11ea-0"},{"nodeId":"ec4ce2ce-2626-11ea-1"},{"nodeId":"ec4ce2ce-2626-11ea-2"},{"nodeId":"ec4ce2ce-2626-11ea-3"}]
[{nodeId:"ec4ce2ce-2626-11ea-0"},{nodeId:"ec4ce2ce-2626-11ea-1"},{nodeId:"ec4ce2ce-2626-11ea-2"},{nodeId:"ec4ce2ce-2626-11ea-3"}]
自我推翻 发现 apoc 有json转map对象
apoc 3.5
//apoc.convert.fromJsonList 转jsonArray
with apoc.convert.fromJsonList('[{"nodeId":"ec4ce2ce-2626-11ea-ad00-0242ac1e4105"}]') as value
return value[0].nodeId
//apoc.convert.fromJsonMap 转jsonObject
with apoc.convert.fromJsonMap('{"nodeId":"ec4ce2ce-2626-11ea-ad00-0242ac1e4105"}') as value
return value.nodeId