Tôi có một chức năng đám mây được sử dụng để tham chiếu hai danh sách và tìm các giá trị khớp với nhau trên danh sách. Chức năng này có vẻ hoạt động bình thường, tuy nhiên trong nhật ký tôi vẫn thấy số Error serializing return value: TypeError: Converting circular structure to JSON
này. Đây là chức năng ...Chức năng đám mây cho Firebase - Lỗi nối tiếp giá trị trả về:
exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => {
if (event.data.previous.exists()) {
return null;
}
const userContacts = event.data.val();
const completionRef = event.data.adminRef.root.child('completed-cross-ref').child(userId);
const removalRef = event.data.ref;
var contactsVerifiedOnDatabase ={};
var matchedContacts= {};
var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers');
return verifiedNumsRef.once('value', function(snapshot) {
contactsVerifiedOnDatabase = snapshot.val();
for (key in userContacts) {
//checks if a value for this key exists in `contactsVerifiedOnDatabase`
//if key dioes exist then add the key:value pair to matchedContacts
};
removalRef.set(null); //remove the data at the node that triggered this onWrite function
completionRef.set(matchedContacts); //write the new data to the completion-node
});
});
Tôi đã thử đưa return
trước completionRef.set(matchedContacts);
nhưng vẫn mang lại cho tôi lỗi. Không chắc chắn những gì tôi đang làm sai và làm thế nào để thoát khỏi lỗi. Nhờ sự giúp đỡ của bạn
Ok tôi sẽ thử điều này. Bạn có thể giải thích 'Promise.all ([...])' là gì không? – MikeG
@MikeG Để tìm hiểu về các lời hứa và cách chúng hoạt động với Chức năng đám mây, hãy xem blog này bằng video được nhúng: https://firebase.googleblog.com/2017/06/keep-your-promises-when-using-cloud.html –
@MichaelBleigh Tôi vẫn gặp lỗi tương tự sau khi thử số này – MikeG