2014-05-22 62 views
0

Tryng可以使用Firebase中的「Where」風格得到一個簡單的結果,但在時間無效的情況下,任何人都可以提供幫助嗎?Firebase「Where」like search

http://jsfiddle.net/vQEmt/68/

new Firebase("https://examples-sql-queries.firebaseio.com/messages") 
.startAt('Inigo Montoya') 
.endAt('Inigo Montoya') 
.once('value', show); 

function show(snap) { 
    $('pre').text(JSON.stringify(snap.val(), null, 2)); 
} 

回答

2

Looking at the applicable records,我看到.priority設置爲時間戳,而不是用戶名。

因此,您無法在這裏嘗試啓動/結束用戶名。這些僅適用於.priority字段。隨着Firebase API的增強功能不斷推出,這些功能將在明年大幅擴展。

現在,對於字段的任意搜索,您最好的選擇是使用搜索引擎。這很容易讓一個人旋轉起來,讓搜索引擎的全部力量觸手可及,而不是用冰河的SQL式的查詢。看起來你已經無意中發現了該主題的appropriate blog posts

當然,您可以使用一個按名稱列出用戶並存儲其所有後期ID的鍵的索引。而且,考慮到這是一個非常小的數據集 - 小於100k - 甚至可以抓住整個事物並在客戶端上搜索它(更大的數據集可以使用endAt/startAt/limit來獲取最近的消息子集):

new Firebase("https://examples-sql-queries.firebaseio.com/messages").once('value', function(snapshot) { 
    var messages = []; 
    snapshot.forEach(function(ss) { 
     if(ss.val().name === "Inigo Montoya") { 
     messages.push(ss.val()); 
     } 
    }); 
    console.log(messages); 
}); 

另見:Database-style queries with Firebase