0
我有以下代碼:如何返回Cloudant插入狀態?
updateDocument = (data) => {
Cloudant(CONN_STRING, (err, cloudant) => {
if (err) {
throw new Error('Failed to initialize Cloudant: ' + err.message);
}
let db = cloudant.db.use('my-db')
db.insert(data, (err, result) => {
if (err) {
throw new Error('Failed to initialize Cloudant: ' + err.message);
}
else {
console.log(result);
}
})
});
}
我想爲updateDocument()
返回結果db.insert提供。但是,如果我嘗試返回一個變量,它是未定義的(我相信因爲異步調用)。我試過async
和await
,但我可能沒有正確設置它們,因爲它們也沒有工作。
感謝您的幫助!