Search code examples
iosfirebaserubymotion

RubyMotion Firebase (motion-firebase) How to query a single key


I've been using

firebase.once(:value) { |snapshot| }

to query my data to this point. But now there's a serious performance issue as my data set is getting bigger.

I already know what keys I need to query, I'd rather just loop through a hand full of calls to Firebase to grab the values of the keys I need.

I'm looking for the appropriate motion-firebase call to achieve this.

Thanks.


Solution

  • You just need to create a new Firebase reference that points to that key or URL.

    firebase = Firebase.new(YOUR_FIREBASE_URL)
    keys = ["key1", "key2"]
    
    keys.each do |key|
      firebase[key].once(:value) do |snapshot|
        puts "#{key} is now #{snapshot.val}"
      end
    end
    

    The important bit there is firebase[key], which is a shorthand for the SDK method firebase.childByAppendingPath(key) (firebase.child(key) does the same thing).