如何读取和比较firebase实时数据库的两个节点的数据?

时间:2018-02-15 09:30:36

标签: node.js firebase google-app-engine firebase-realtime-database google-cloud-functions

如何从firebase中的实时数据库中读取数据。 我有两个不同的节点,两个节点都有几个pushIds,每个pushId在两个节点中只有Email列!我想将节点1中的所有电子邮件逐个比较到节点2的电子邮件,如果两者不相等则在firebase中创建新节点并将该电子邮件放入新创建的节点中。[https://i.stack.imgur.com/zkSpU.png]

我想从MyloRingFencedUsers节点检查DailyAnswerersNeedToChekInRingFencedList。 我正在尝试的代码是

exports.sendBigQData = 
functions.analytics.event('event_name').onLog(event => {

const bigQuery = bigquery({ projectId: '' });

bigQuery.query({
query: 'Select Email from (Select Email, NoOfDays from (select Email, 
count( case when number_answers="answered_a_question" then event_date 
ELSE NULL END) as NoOfDays from (SELECT   user.value.value.string_value 
as Email,CAST(TIMESTAMP_ADD(TIMESTAMP_MICROS(event.timestamp_micros), 
INTERVAL 330 MINUTE) AS date) AS event_date,(event.name) AS 
number_answers FROM 
`*`,UNNEST(event_dim) AS event,  UNNEST(user_dim.user_properties) AS 
user WHERE event.name="answered_a_question" and user.key="email"   and 
CAST(TIMESTAMP_ADD(TIMESTAMP_MICROS(event.timestamp_micros), INTERVAL 
330 MINUTE)AS date) between DATE_SUB(current_date(), INTERVAL 9 DAY) 
and DATE_SUB(current_date(),INTERVAL 3 DAY) GROUP By 
event_date,Email,number_answers)GROUP By Email)where NoOfDays>=6)',

useLegacySql: false
}).then(function (results) {
var ref = admin.database().ref("MyloRingFencedUsers");
var rows = results[0]; //get all fetched table rows
rows.forEach(function(row){ //iterate through each row
ref.push().set({ //
Email:row['Email'],
});});});

const bigQueryone = bigquery({ projectId: '' });
bigQuery.query({
query: 'Select distinct EmailID from(SELECT count(event.name) as 
noofanswers,user.value.value.string_value as EmailID,
substr(cast(TIMESTAMP_ADD(TIMESTAMP_MICROS(event.timestamp_micros), 
INTERVAL 330 MINUTE) as string),1,10) AS event_date FROM ``,
UNNEST(event_dim) AS event, UNNEST(user_dim.user_properties) AS user 
WHERE event.name = "answered_a_question" AND user.key = "email" and 
CAST(TIMESTAMP_ADD(TIMESTAMP_MICROS(event.timestamp_micros), INTERVAL 
330 MINUTE)AS date) between DATE_SUB(current_date(), INTERVAL 1 DAY) 
and DATE_SUB(current_date(),INTERVAL 0 DAY)group by 
EmailID,event_date)order by 
EmailID',

useLegacySql: false
}).then(function (results) {
var ref = admin.database().ref("Daily Answerers Need To Chek In Ring 
FencedList");
var rows = results[0]; //get all fetched table rows
rows.forEach(function(row){ //iterate through each row
ref.push().set({ 
EmailID:row['EmailID']
})
})
 if (1)
  {
 var ref = admin.database().ref("NonAnswerers");
 console.log("node created")
    }
 return 0;   
    });

    });

无法在if条件下创建第三个节点

0 个答案:

没有答案