2017-02-28 39 views
0

我嘗試使用全局函數,我可以使用一些mysql函數,但問題是,js說「.then」是未定義的,是什麼讓我錯了,這只是一個語法錯誤?Node.js無法讀取未定義的屬性'then'

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的幫助:)

+0

我猜'connectWidthCortex()'的返回值不是承諾。你可以檢查一下嗎? – GPX

回答

2

您正在試圖調用then上的connectWidthCortex返回值。

connectWidthCortex功能沒有return聲明,所以它返回undefined

如果您想返回致電getSession給您的承諾,那麼您需要一個return聲明。

return xdevapi.getSession({ …

相關問題