【问题标题】:Firebase "Where" like searchFirebase“在哪里”喜欢搜索
【发布时间】:2014-07-11 19:59:50
【问题描述】:

尝试在 firebase 中使用“Where”样式获得简单的结果,但始终为 null,任何人都可以提供帮助吗?

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));
}

【问题讨论】:

    标签: firebase


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      相关资源
      最近更新 更多