Today we're launching enhanced query support across our iOS, Android, and Web clients, and the Firebase REST API! You can now query your data by any child key in Firebase. Querying has been a frequently requested feature and we’ve made great strides based on developer feedback since our beta release last month.
This release dramatically improves the way you can query your data in Firebase. With our new querying methods you can order and retrieve your data using a child key, by key name, or by priority. Our existing priorities-based ordering will continue to work, but I encourage you to try out the new queries features as it is much more flexible.
A basic Firebase query starts with one of our orderBy functions: orderByChild(), orderByKey() or orderByPriority(). You can then combine these with five other methods to conduct complex queries: limitToFirst(), limitToLast(), startAt(), endAt(), and equalTo(). Since all of us at Firebase agree that dinosaurs are pretty cool, we’ll use this sample firebase of dinosaur facts to demonstrate how you can write complex, realtime queries. To start, we can use orderByChild() to retrieve dinosaurs ordered by height:
orderByChild()
orderByKey()
orderByPriority()
limitToFirst()
limitToLast()
startAt()
endAt()
equalTo()
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); ref.orderByChild("height").on("child_added", function(snapshot) { console.log(snapshot.key() + " was " + snapshot.val().height + " meters tall"); });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://dinosaur-facts.firebaseio.com/dinosaurs"]; [[ref queryOrderedByChild:@"height"] observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) { NSLog(@"%@ was %@ meters tall", snapshot.key, snapshot.value[@"height"]); }];
Firebase ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); Query queryRef = ref.orderByChild("height"); postsQuery.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot snapshot, String previousChild) { System.out.println(snapshot.getKey() + " was " + snapshot.getValue().get("height") + " meters tall"); } // .... });
curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="height"'
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) { console.log(snapshot.key()); });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://dinosaur-facts.firebaseio.com/dinosaurs"]; [[[ref queryOrderedByChild:@"weight"] queryLimitedToLast:2] observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) { NSLog(@"%@", snapshot.key); }];
Firebase ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); Query queryRef = ref.orderByChild("weight").limitToLast(2); queryRef.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot snapshot, String previousChild) { System.out.println(snapshot.getKey()); } // .... });
curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="weight"&limitToLast=2'
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) { console.log(snapshot.key()) });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://dinosaur-facts.firebaseio.com/dinosaurs"]; [[[ref queryOrderedByChild:@"height"] queryStartingAt:@3] observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) { NSLog(@"%@", snapshot.key); }];
Firebase ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs"); Query queryRef = ref.orderByChild("height").startAt(3); queryRef.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot snapshot, String previousChild) { System.out.println(snapshot.getKey()); } // .... });
curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="height"&startAt=3'
The best part is that all these queries will update in realtime as the data changes in your Firebase. There’s more I haven’t covered, so be sure to read the documentation for the iOS, Android or Web clients or the REST API to learn about all the new features.
With querying, we’re also introducing a new indexOn rule type to the Firebase Security and Rules language. You can use indexOn to tell your Firebase which child keys your app uses in queries. A node's key and and priority are indexed automatically, so there is no need to index them explicitly. Using indexOn is optional and can be left off for prototyping, but it will dramatically improve performance so you'll want to add it once you've figured out the indexes your queries will use.
While this represents a big step forward in terms of our querying capabilities it also lays the groundwork for even more improvements. We have a number of exciting features in the pipeline for our SDKs, including more queries improvements. And as always, we'd welcome your feedback on what you'd like to see next.
Let us know what you think in our Google Group or on Twitter, and send any suggestions to firebase-support@google.com.
Over the past three years, we’ve gone from a crazy idea that ‘just might work’ to a proven product used by 110,000 developers. Today, I couldn’t be happier to announce that we’ve joined Google.
Two big reasons.
First, Google’s backing allows us to dramatically scale Firebase. We’re proud of what we’ve built over the last three years, but we’ve only scratched the surface of the opportunity ahead of us. With Google’s engineering talent, resources, and technical infrastructure, we’ll be able to do much more, much faster.
Second, our products and missions are highly complementary. Both the Firebase and Google Cloud Platform teams come to work each day for the same reason: to help developers create extraordinary experiences. By joining forces, Firebase developers will gain access to a powerful cloud infrastructure suite, and Cloud Platform customers will gain access to our rapid development capabilities. Together we’ll deliver a complete platform for mobile and web apps.
Firebase is here to stay and grow. You can continue to count on the same great development experience, tools, libraries and community commitment that have become synonymous with Firebase. If you’re a developer who has built an app on top of Firebase, nothing will change for you, and you can continue to use Firebase as you normally would. We’ll continue to be platform agnostic and provide clients for iOS, Android, the web, and more.
To our developer community, thank you. Building Firebase has been a challenge and you’ve helped immensely with your encouragement and support. Thank you for your API feedback, answering StackOverflow questions, submitting pull requests to our open source projects, and building your apps on Firebase. Many of you have bet your startups and careers on us -- we’re constantly humbled by this and look forward to serving you for many years to come.
You can read Google’s announcement here. Also, we'll be sharing more at Google Cloud Platform Live on November 4th in San Francisco. We'd love for you to join us in person to meet our team and learn about the great things we're working on. If you can't make it, don't worry - everything will be streamed live.
Finally, if you’d like to come and help us write the next chapter of Firebase, we’re hiring.
Happy coding,
James TamplinCo-Founder & CEO
With the fall hackathon season underway, we’ve had a chance to introduce a ton of talented college students to Firebase. We continue to be amazed by the hacks students are building in just a few hours (with barely any sleep!).
Last month we participated in MHacks, where students used Firebase to build things like “collaborative graffiti via text” and “real world Pokemon”. At CalHacks this past weekend, the best hardware hack used Firebase for a shirt that tracks your posture in realtime. See below for a recap of our favorite Firebase hacks from MHacks and CalHacks.
Abe, Chris, Joey and Mike from Firebase traveled to Ann Arbor, Michigan to support 1,100+ hackers from across the country at MHacks. At the end of the hackathon, 34 teams used Firebase to store and sync their app’s data in realtime. These were the Firebase top two:
Our top prize went to VoteApp, a web based voting platform where users can create a new poll and display the results in realtime. Designed to replace an expensive and specialized device currently used for voting in class, these four students wanted to build a universal and free solution. Use it to run your next classroom poll, it’ll be the easiest one you’ve ever done!
Our second place prize went to City Paint, which aims to reduce the prevalence of graffiti in urban areas by creating an online graffiti wall. These virtual walls can be placed around cities, and residents can text ASCII art to the wall and watch as their tags are added in realtime.
Over half of the Firebase team had the opportunity to meet the 1,000+ hackers at the amazing Cal Memorial Stadium last weekend. We had a great time helping hackers, and were impressed by their uses of the Firebase API. Both winners of our prize connected hardware to Firebase for realtime IoT awesomeness.
The Nextile Shurt team built a device with flex sensors and accelerometers that ran on two Intel Edison boards. It captured motion data in realtime and displayed the data on a web app. The best part? They attached their device to a shirt, so that when you move the degree of motion is stored in Firebase. It can be used to track posture or for physical therapy.
Our second place prize went to the Pomsafe team. Pomsafe is a home security and automation platform running from a Texas Instruments LaunchPad, powered by Firebase. When the device is attached to a door, it monitors temperature in realtime and reports when the door is opened to detect possible break-ins.
We're always excited to see what students build with Firebase in such a short amount of time, and we can't wait for the next hackathon! Follow us @Firebase on Twitter to find out which hackathons we'll be attending next.
“In addition to giving developers near real-time access to our data, we got out of the box well designed, easy to use SDKs for iOS, Android and the Web, in addition to a REST API for developers building server apps. It should hopefully making switching your apps fairly painless.”
var ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); var itemRef; ref.child('topstories').child(0).on('value', function(snapshot) { if(itemRef) { itemRef.off(); } //Get the ID of the top article var id = snapshot.val(); //Get the article details and update in realtime itemRef = ref.child('item').child(id); itemRef.on('value', function(snapshot) { var item = snapshot.val(); document.getElementById("score").innerHTML = item.score; var anchor = document.getElementById("article_a") anchor.innerHTML = item.title; anchor.href = item.url; document.getElementById("comments_a").href = "https://news.ycombinator.com/item?id=" + item.id; }); });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://hacker-news.firebaseio.com/v0/"]; __block Firebase *itemRef = nil; Firebase *topStories = [ref childByAppendingPath:@"topstories"]; Firebase *firstStory = [topStories childByAppendingPath:@"0"]; FirebaseHandle handle = [firstStory observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { if(itemRef != nil) { [itemRef removeObserverWithHandle: handle]; } NSString *itemId = [NSString stringWithFormat:@"item/%@",snapshot.value]; itemRef = [ref childByAppendingPath:itemId]; [itemRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *itemSnap) { NSLog(@"%@", itemSnap.value); }]; }];
final Firebase ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); final Map<Long, ValueEventListener> valueEventListenerMap = new HashMap(); ref.child("topstories").child("0").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if(!valueEventListenerMap.isEmpty()) { for(Long id : valueEventListenerMap.keySet()) { ref.child("item").child(String.valueOf(id)).removeEventListener(valueEventListenerMap.get(id)); } valueEventListenerMap.clear(); } //Get the ID of the top article Long id = (Long) snapshot.getValue(); //Get the article details and update in realtime ValueEventListener articleListener = ref.child("item").child(String.valueOf(id)).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Map itemMap = (Map) snapshot.getValue(); // Print the title to the console System.out.println(itemMap.get("title")); } @Override public void onCancelled(FirebaseError firebaseError) { } }); valueEventListenerMap.put(id, articleListener); } @Override public void onCancelled(FirebaseError firebaseError) { } });
Check out the full HN documentation at hacker-news.firebaseapp.com.
With more than 100,000 developers using our platform, we’ve seen Firebase used both as the entire backend for apps as well as to power specific realtime features in apps. A growing use case has been loading data into Firebase to expose an API to other developers. Traditionally, building and maintaining a public API is a big undertaking; often entire teams are dedicated to it. It’s not easy to give third party developers access to your data in a way that’s both safe for your users and powerful for those developers. With Firebase, all you need to do is sync data to your Firebase and API consumers can then use one of Firebase’s realtime clients or the REST API to consume that data. You don’t have to worry about scaling with developer usage and or documenting anything beyond your data structure. You can learn more in a blog post we published last year.
We can’t wait to see what you build!
Last week, we released v1.0.0 of our open-source apps Firepad and Firechat! These are two great open-source modules built on top of Firebase that you can take and use in your own apps.
Firepad is a collaborative text editor. It lets you bring the features of Google Docs right into your app. Firepad can handle both code and rich text, and is currently being used in production by Atlassian, LiveMinutes, and CoderPad to name a few.
Firechat is a realtime chat app built with Firebase. Firechat’s features include multi-user / multi-room chat, flexible authentication, moderation, presence, private messaging, chat invitations and more. CBS is using Firebase to power the realtime chat for their Big Brother TV series.
Orginally we built both of these modules to showcase the realtime and collaborative power of Firebase, but they’ve grown into full-featured, production-ready pieces of functionality. Both projects have reached the point where they’re stable, full-featured and well-documented, so we’ve decided to officially tag them as 1.0!
Here's what's new in the 1.0.0 releases:
With help from the community, we’ve added some highly-requested features and fixed many bugs over the past few months.
We added a headless mode for interacting with documents programmatically with no GUI (e.g. from your backend server code). It can run in Node or in a browser. To use it from Node, just run npm install firepad, require the module, and add a headless instance of Firepad using the following code:
npm install firepad
var Firepad = require('firepad'); var headless = new Firepad.Headless('');
We've made a number of API improvements to make writing apps using Firepad easier. For instance, there's a new defaultText option to specify initial text to be loaded in Firepad, and there's a new "synced" event to notify you when your changes have successfully been synced with Firebase so you can provide notice to the user. See the API docs for full details.
defaultText
We've also fixed many minor bugs and UI issues to make the collaborative editing as fluid and seamless as possible! Firepad is now available on the Firebase CDN as well as Bower, making it even easier to include in your app.
Our Firechat homepage is now hosted on Firebase Hosting. In addition to this, we’ve improved the documentation, fixed bugs, and added warning messages to make development easier. Firechat now works well with other frameworks like Twitter Bootstrap, so you can customize the app’s default styling.
If you’re using Firepad or Firechat in your apps, we’d love your input. Email us any feedback at firebase-support@google.com or submit a pull request on GitHub. We’re excited to see what you build!