【发布时间】:2017-12-01 02:38:57
【问题描述】:
我有一个云函数用于交叉引用两个列表并在列表中查找相互匹配的值。该功能似乎工作正常,但是在日志中我一直看到这个 Error serializing return value: TypeError: Converting circular structure to JSON 。这是函数...
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
});
});
我尝试将return 放在completionRef.set(matchedContacts); 前面,但这仍然给了我错误。不知道我做错了什么以及如何消除错误。感谢您的帮助
【问题讨论】:
标签: javascript node.js firebase firebase-realtime-database google-cloud-functions