简体   繁体   English

通过javascript API将对象插入neo4j

[英]Insert an object to neo4j via javascript API

How can I insert an entire object into Neo4J using JS API? 如何使用JS API将整个对象插入Neo4J? (without providing each and every property) (不提供每个属性)

I've tried the following.( link ) 我已经尝试了以下。( link

session.run('UNWIND $obj as obj2 \n CREATE (p:Animals) \n set p=obj2 \n RETURN p', { obj: results.value })

where results.value = {id:"abc", name:"xyz", createdOn: new Date()} 其中results.value = {id:"abc", name:"xyz", createdOn: new Date()}

But it gives the following error 但是它给出了以下错误

Neo4jError: Property values can only be of primitive types or arrays thereof Neo4jError:属性值只能是原始类型或其数组

Can anyone help on this? 有人可以帮忙吗?

Neo4j database supports properties of types ( docs ): Neo4j数据库支持类型的属性( docs ):

  • Integer 整数
  • Float 浮动
  • String
  • Boolean 布尔
  • List of these types 这些类型的清单

Probably the object stored in results.value has a property containing a complex object, something like: 可能存储在results.value的对象可能具有包含复杂对象的属性,例如:

{
    prop1 : 1
    complexProp : {
        propX : "abc",
        propY : 1,
    }
}

In the case of the above structure, the complexProp property will be the cause of your error because its type not fits in any Neo4j supported types. 在上述结构的情况下, complexProp属性将是导致错误的原因,因为其类型不适合任何Neo4j支持的类型。

So I think you have two alternatives. 所以我认为您有两种选择。

1 - Move all sub-properties to the root, like: 1-将所有子属性移至根,​​例如:

 {
     prop1 : 1
     propX : "abc",
     propY : 1
 }

2 - Create a different node type for complexType property and use a relation between the two nodes. 2-为complexType属性创建不同的节点类型,并在两个节点之间使用关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM