2016-06-24 3 views
0

RSS 피드에서 데이터를 가져와 Firebase의 데이터베이스에 구조화 된 날짜로 추가하고 있습니다. RSS 피드가 새로 고침 될 때마다 새 UID가 추가되지만 문제는 동일한 값을 추가한다는 것입니다. 즉 : Firebase 데이터베이스에서 복제본 건너 뛰기

enter image description here

에 값이 있는지 확인하는 방법, 예를 들어,이 있습니까 업데이트 : "Fish showing all .."이 (가) 이미 존재하며 대신 완전히 새로운 UID를 추가하지 마십시오. 구문 분석 된 피드를 사용하도록되어

feedparser.on('readable', function() { 
    // This is where the action is! 

    var stream = this 
    , meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance 
    , item; 

    while (item = stream.read()) { 

     console.log(item); 


var pubDate = item.pubDate; 
    var date = new Date(pubDate); 
    var description = item.description; 

var parts = description.split(' - ', 2); 

var time = parts[0]; 
var update = parts[1]; 


    // date.setTimezone 
    // var time = date.getHours()+":"+date.getMinutes(); 


     var monthNames = ["January", "February", "March", "April", "May", "June", 
    "July", "August", "September", "October", "November", "December" 
         ]; 

     var month = monthNames[date.getMonth()]+" "+date.getDate(); 

     var postData = { 
     time: time, 
     date: month, 
     update: update, 
     description: description, 
     day: pubDate 

    }; 


var newPostKey = firebase.database().ref().child('feed').push().key; 
    var updates = {}; 
    updates['/feed/' + month + '/' + newPostKey] = postData; 
    return firebase.database().ref().update(updates); 
+0

특정 값이 고유하다는 것을 보장하려는 것 같습니다 : http://stackoverflow.com/questions/25294478/how-do-you-prevent-duplicate-user-properties-in-firebase –

답변

0

여기에 솔루션, 내가 생각 :

나는 RSS 구문 분석에 대한 feedparser (Node.js를)를 사용하고 있는데이 모든 새로 고침 중복을 일으키는 코드 데이터를 사용하여 일종의 고유 한 식별자를 얻고이를 푸시를 사용하는 대신 Firebase 데이터베이스 키로 사용하십시오. 예를 들어, 많은 RSS 고유 게시물을 식별하는 guid 값이 피드, 그래서 당신은 같은 것을 할 수있을 것 : 너무 오래 guid은 당신이 동일한 항목을 여러 번 가져 오는 경우,

firebase.database().ref('feed') 
    .child(month).child(postData.guid) 
    .update(updates); 

그 방법을 동일하게 업데이트됩니다.

+0

내가 할 수있는 ' 내가 이것을 생각하지 않는다고 생각하지 마라. 감사합니다! – HalesEnchanted