ref
함수 실행이 완료된 후 어떻게 제거 할 수 있습니까? 그게 필요 할까? 내 기능이 가능한 한 빨리 실행되기를 원하고 "사물"이 쌓이는 것을 원하지 않습니다.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.myFunction = functions.database.ref('/path/{uid}').onWrite(event => {
const ref = event.data.adminRef.root.child('something').child(event.params.uid);
return ref.transaction(current => {
if (event.data.exists() && !event.data.previous.exists()) {
return _.toInteger(current) + _.toInteger(_.get(data, 'value', 0));
}
}).then(() => {
return null; // Avoid "Error serializing return value: TypeError: Converting circular structure to JSON"
});
});
A DatabaseReference
는 "제거"할 수 있는 것이 아닙니다. 데이터베이스의 위치에 대한 포인터 일뿐입니다. 문서에는 https://firebase.google.com/docs/reference/admin/node/admin.database.Reference 페이지가 있습니다.
제거 / 분리 할 수있는 유일한 것은 ref.on(...)
,로 설정 한 콜백 ref.off(...)
이지만 코드에는 콜백이 없으므로 ref.once()
함수에서 대부분의 경우 작업을 완료해야 한다고 생각합니다 .
명확 ref.transactions()
하게 말하면,은 분리 할 필요가 없으며 한 번만 실행됩니다. 즉, 콜백이 없습니다. 동일에 ref.set()
와 ref.once()
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다