답변

0

내가 원하는 효과 이런 식으로있어 :

transaction.run(function(err) { 
    if (err) { 
     res.end(err); 
    } 

    transaction.get(key, function(err, entity) { 
     if (err) { 
      res.end(err); 
     } 
     if (entity) { 
      entity.ImportStatus = InputImportStatus; 
     } else { 
      res.end('No Entity err'); 
     } 

     transaction.save({ 
      key: key, 
      data: entity 
     }); 

     transaction.commit(function(err) { 
      if (!err) { 
       res.send(`Updated`) 
      } else { res.end(err); } 
     }); 
    }); 
}); 
1

엔티티를 읽고 값을 업데이트하고 엔티티를 쓰는 곳에서 트랜잭션을 수행하고자 할 것입니다.

function updateEntity (updateKey, newValue) { 
    const transaction = datastore.transaction(); 

    return transaction.run() 
    .then(() => transaction.get(fromKey)) 
    .then((result) => { 
     const entity = result[0]; 

     entity.myProperty = newValue; 

     transaction.save(
     { 
      key: updateKey, 
      data: entity 
     } 
    ); 

     return transaction.commit(); 
    }) 
    .catch(() => transaction.rollback()); 
} 
+0

난 아직 업데이트를 할 수없는 걸, 나는 { "textPayload"'를 얻을 : "약속 {}", "insertId": "000000 - f365b507-72d8-48e2-a3ce-f65052545bb6", "자원": { "유형": "cloud_function" "라벨": { "PROJECT_ID": "***** * ", "지역 ":"us-central1 ", "function_name ":"UpdateImportLog " } }, "타임 스탬프 ":"2017-09-25T11 : 57 : 45.233Z " "심각 ":"INFO ", "라벨 ": { "execution_id ":"xci8wzhqkbqj " }, "logName ":"projects/crypto-analyzer-180608/logs/cloudfunctions.googleapis.com % 2Fcloud-functions ", "receiveTimestamp ":"*** " } –

관련 문제