我必须在我的Firebase数据库中使用云功能执行查询,然后返回Json格式的对象列表。
但目前我甚至无法正确查询......
我在Node下有一个UserIds列表,每个UserId节点下面是一个对象列表,我需要抓取一个具有特定值的对象列表。
它是这样的:
"rewardTransactions" : {
"Lu9XzBzGK2Q42ml8TstACwzusq1" : {
"-LDeJgAYjDBDRqa4E7Hn" : {
"transaction_date" : "9/3/18",
"transaction_points" : "400",
"transaction_recipient_index" : "2",
"transaction_status" : "PROCESSED",
"transaction_value" : "$40.00"
},
"-LDeJhvkRp25k_0xpP77" : {
"transaction_date" : "20/4/18",
"transaction_points" : "100",
"transaction_recipient_index" : "2",
"transaction_status" : "PENDING",
"transaction_value" : "$10.00"
}
},
"W6RTEnn7haN937HaPmwKXpZPN7f1" : {
"-LDeJgg1pi00IvceTFIi" : {
"transaction_date" : "16/3/18",
"transaction_points" : "300",
"transaction_recipient_index" : "1",
"transaction_status" : "PROCESSED",
"transaction_value" : "$30.00"
},
我需要获取所有具有" transaction_status "的交易。价值" 待定"。 但到目前为止,没有成功。
这是我的云功能:
export const getPendingTransactions = functions.https.onRequest((request,response) =>{
const ref = admin.database().ref('/rewardTransactions/');
const pendingTransactionsQuery = ref.orderByChild('transaction_status').equalTo("PENDING");
return pendingTransactionsQuery.once('value').then(result =>{
console.log(result.val());
});
});