My goal is to create an Atlas triggers to synchronize my MongoDB database with a Neo4j (Aura) database. The function I wrote works fine on my computer, however, when called by the trigger it throws this error:
TypeError: Configured resolver function should either return an array of addresses or a Promise resolved with an array of addresses.Each address is '<host>:<port>'. Got: [object Promise]
This is the function:
(async () => {
const neo4j = require("neo4j-driver");
const uri = "neo4j+s://d3dc4645.databases.neo4j.io";
const user = "neo4j";
const password = "...";
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session();
const id = "TEST"
const writeQuery = `MERGE (p1:User {id:$id })`;
await session.writeTransaction((tx) => tx.run(writeQuery, { id }));
await driver.close();
})();
In the trigger it is like this (this doesn't work):
exports = async function(changeEvent) {
const neo4j = require("neo4j-driver");
const uri = "neo4j+s://d3dc4645.databases.neo4j.io";
const user = "neo4j";
const password = "...";
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session();
const id = "TEST"
const writeQuery = `MERGE (p1:User {id:$id })`;
await session.writeTransaction((tx) => tx.run(writeQuery, { id }));
await driver.close();
};
I honestly have no idea what the problem is. I can guess that it derives from some incompatibility of that dependence or in any case, is linked to the way in which promises are managed. What am I doing wrong?
It's still a limiting problem for me...
Update after the reply of @NBekelman.
I have already tried in the following days to change the code but unfortunately, the error message is always the same.
exports = function(changeEvent) {
[...]
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session({ defaultAccessMode: neo4j.session.WRTIE });
console.log(session); // <-- so far so good
const writeQuery = `MERGE (p1:User {id:"TEST" })`;
session.run(writeQuery) // <-- error
.then(result => {
console.log(result);
})
.then(() => session.close());
driver.close();
};
You are returning a Promise but the function you are using expect to a value (by the error, the type should be <host>:<port>;
Also I think you should use
module.exports = ... // default exports
exports.handler = ... // named exports
Publish the consumer of this function for more help if needed.