Reputation: 1421
How can I insert an entire object into Neo4J using JS API? (without providing each and every property)
I've tried the following.(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()}
But it gives the following error
Neo4jError: Property values can only be of primitive types or arrays thereof
Can anyone help on this?
Upvotes: 0
Views: 170
Reputation: 16365
Neo4j database supports properties of types (docs):
Probably the object stored in results.value
has a property containing a complex object, something like:
{
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.
So I think you have two alternatives.
1 - Move all sub-properties to the root, like:
{
prop1 : 1
propX : "abc",
propY : 1
}
2 - Create a different node type for complexType
property and use a relation between the two nodes.
Upvotes: 1