Trying to run multiple queries inside of Streaming API

Hello,

I need to remodel a property on some nodes in my database using the neo4j typescript driver. The process looks something like:

  1. Read the existing nodes in the database
  2. Process a property of the nodes server side in my application
  3. Write the processed property back to the nodes

Because this has the potential to load a lot of data onto my application server at one time, I am considering using the Streaming API so that I can read records in one at a time using one session, then in the onRecord callback, have another session that writes the processed records back to the database. See example below:


session
  .run('MATCH (p:Person) RETURN p.name AS name')
  .subscribe({
    onKeys: keys => {},
    onNext: async record => {
      const name = record.get('name');
      // business logic to process name here.  assume it creates a new variable called newName
      await anotherSession.run('MATCH (p:Person {name:$name}) SET p.name = $newName',{newName:'newName'})
    },
    onCompleted: () => {
      session.close() // returns a Promise
      newSession.close()
    },
    onError: error => {
      console.log(error)
    }
  })

This approach throws the following error

unhandledRejection: You cannot begin a transaction on a session with an open transaction; either run from within the transaction or use a different session.
Neo4jError: You cannot begin a transaction on a session with an open transaction; either run from within the transaction or use a different session.

Is my approach the best way to handle this scenario?

I already looked into whether or not I can do the processing in the database, and it doesn't seem possible, so I need to load the data onto my server.

Thanks.

1 Like