cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to make transaction with for loops

Hello, i'm learning neo4j and i have a problem for a school project

  1. can someone explain me how to make multiples transactions with for loop?
  2. how to handle .then and .catch (duplicate constraint on neo4j applied ) ?
  3. is it a good example to use Promise.all ?

Thanks


This is a portion of my code but there is an error :
(node:3622) UnhandledPromiseRejectionWarning: Neo4jError: The transaction has been terminated. Retry your operation in a new transaction,


const createMultiplesCategories=(req,res)=>{
const {allMenus}=req.body
console.log(allMenus)
allMenus.forEach(menu => {
const session = driver.session()
const {name,color}=menu
session.writeTransaction(transaction=> {
return transaction.run(CREATE (n:CATEGORY{ name:'${name}', color: '${color}' }));
})
session.close();
});
}


the request JSON(BODY)


{
"allMenus":[
{"name":"FISH","color":"bg-light-pink"},
{"name":"SALAD","color":"bg-light-green"},
{"name":"APPETIZERS","color":"bg-washed-red"},
{"name":"VEGETARIAN DISHES","color":"bg-light-red"},
{"name":"BEVERAGES","color":"bg-light-pink"},
{"name":"ICE CRAM","color":"bg-light-green"},
{"name":"HAMBURGER","color":"bg-washed-red"},
{"name":"PIZZA","color":"bg-light-red"}
}

0 REPLIES 0