Reputation: 33
I try to use a global function where i can use for some mysql functions, but the problem is that js say that the ".then" is undefined, what make i wrong, is this only an syntax error?
static connectWidthCortex(){
xdevapi.getSession({
host: 'localhost',
port: 33060,
dbUser: 'admin',
dbPassword: 'xxxx'
}).then((session)=> {
return session.getSchema("cortex");
});
};
static createCollection(collname){
this.connectWidthCortex().then((db)=> {
console.log("Cortex connected")
return db.createCollection(collname);
}).catch((err)=> {
console.log("connection failed")
});
}
Thx for help :)
Upvotes: 3
Views: 11959
Reputation: 943579
You are trying to call then
on the return value of connectWidthCortex
.
The connectWidthCortex
function doesn't have a return
statement, so it returns undefined
.
If you want to return the promise that calling getSession
gives you, then you need a return
statement.
return xdevapi.getSession({ …
Upvotes: 8