Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>The Idea</h1> <p>A near solution is to create an index of your data which is indexed by City (or whichever other field you'd like to search by) in a server-side NodeJS script. </p> <p>This will <em>not quite</em> replicate the behavior of <code>LIKE</code>, however it will allow for easy querying by City name, which may eliminate the need for that behavior.</p> <h1>The Node Script</h1> <p>This is typically done via a simple server-side script written in NodeJS. Imagine a scenario where your user data was stored in <code>/users/data</code>. Your script would look like this.</p> <pre><code>var ref = new Firebase("&lt;Your Firebase&gt;.firebaseio.com"); // A Firebase ref where all our users are stored var userDataRef = ref.child('users/data'); // A Firebase ref which is where we store our index var byCityRef = ref.child("users/byCity"); // Then bind to users/data so we can index each user as they're added userDataRef.on("child_added", function (snapshot) { // Load the user details var user = snapshot.val(); // Use the snapshot name as an ID (i.e. /users/data/Tim has an ID of "Tim") var userID = snapshot.name(); // Push the userID into users/byCity/{city} byCityRef.child(user.city).push(userID); }); </code></pre> <p>This script will create a structure like this:</p> <pre><code>{ "users": { "data": { "Tim": {"hair": "red", "eyes": "green", "city": "Chicago"} }, "byCity": { "Chicago": { "-asd09u12": "Tim" } } } } </code></pre> <h1>The Client Script</h1> <p>Once we've indexed our data, querying against it is simple and can be done in two easy steps.</p> <pre><code>var ref = new Firebase("&lt;Your Firebase&gt;.firebaseio.com"); var userDataRef = ref.child('users/data'); var byCityRef = ref.child('users/byCity') // Load children of /users/byCity/Chicago byCityRef.child('Chicago').on("child_added", function (snapshot) { // Find each user's unique ID var userID = snapshot.val(); // Then load the User's data from /users/data/{ID} userDataRef.child(userID).once(function (snapshot) { // userID = "Tim" // user = {"hair": "red", "eyes": "green", "city": "Chicago"} var user = snapshot.val(); }); }); </code></pre> <p>Now you have the near realtime load speed of Firebase with powerful querying capabilities!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload