I'm trying to batch merge to create multiple nodes. Using the below code,
def test_batches(tx,user_batch):
result= tx.run(f"Unwind {user_batch} as user\
MERGE (n:User {{id: user.id, name: user.name, username: user.username }})")
However I am getting this error. Note I'm passing in a list of dictionaries.
CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '[': expected "+" or "-" (line 1, column 8 (offset: 7))
"Unwind [{'id': 1596859520977969156, 'name': 'Bigspuds', 'username': 'bigspuds777'}, {'id': 1596860505662144513, 'name': 'JOHN VIEIRA', 'username': 'JOHNVIE67080352'}, {'id': 1596860610905448449, 'name': 'biru nkumat', 'username': 'NkumatB'}, {'id': 1513497734711738374, 'name': 'elfiranda Hakim', 'username': 'Kidonk182'}, {'id': 1596836234860859392, 'name': 'Ecat Miao', 'username': 'sylvanasMa'}] as user MERGE (n:User {id: user.id, name: user.name, username: user.username })"
^}
I have no idea why this is happening any help is greatly appreciated.
Below is a working code on using UNWIND for a list of dictionaries. Please note that is it recommended to pass the value as a parameter rather than working on the value string in query.
sample result: