Firebase “Where” like search

前端 未结 1 1069
野性不改
野性不改 2021-01-23 10:36

Tryng to get a simple result using \"Where\" style in firebase but get null althe time, anyone can help with that?

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

new Fire         


        
相关标签:
1条回答
  • 2021-01-23 11:09

    Looking at the applicable records, I see that the .priority is set to the timestamp, not the username.

    Thus, you can't startAt/endAt the user's name as you've attempted here. Those are only applicable to the .priority field. These capabilities will be expanding significantly over the next year, as enhancements to the Firebase API continue to roll out.

    For now, your best option for arbitrary search of fields is use a search engine. It's wicked-easy to spin one up and have the full power of a search engine at your fingertips, rather than mucking with glacial SQL-esque queries. It looks like you've already stumbled on the appropriate blog posts for that topic.

    You can, of course, use an index which lists users by name and stores the keys of all their post ids. And, considering this is a very small data set--less than 100k--could even just grab the whole thing and search it on the client (larger data sets could use endAt/startAt/limit to grab a recent subset of messages):

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

    Also see: Database-style queries with Firebase

    0 讨论(0)
提交回复
热议问题