DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Firebase Querying Using AngularJS

Firebase Querying Using AngularJS

Applying certain functions in AngularJS makes it really easy to query your database in order to get the specific results that you need.

Ezequiel Reyno user avatar by
Ezequiel Reyno
·
Feb. 26, 17 · Mobile Zone · Opinion
Like (4)
Save
Tweet
8.02K Views

Join the DZone community and get the full member experience.

Join For Free

I've already done a couple of posts about Firebase and how to use the real-time database and storage with AngularJS. If you missed it, you can check it out here. Today, I want to go further and give you some details on how to querying.

Understanding the Reference Object

As you already know, we can define a reference object just by calling the following functions in the database object: firebase.database().ref(). This reference object offers you a bunch of functions to query our database paths in order to return just a subset of objects.

Using Orderbychild(), Orderbykey(), Orderbypriority(), and Orderbyvalue()

Using this set of functions allows us to create a new query reference that will be sorted by different properties. For example, child will sort the subset by a specific property within the returned data and key is going to sort the subset by the object key.

Using Startat(), Endat(), and Equalto()

Using this set of functions allow us to generate a query with a subset of an object that matches with the specified conditions. For example, we can use equalTo chained with orderByChild in order to sort the subset by a specific property and then filter this subset to the results that match with an specific condition, as I did in the example below.

function getPlacesByUser(uid) {
    if (!places) {
        places = $firebaseArray(firebaseDataService.places.orderByChild('userId').equalTo(uid));
    }
    return places;
}

Applying those functions, as you can see, makes it really easy to query our database in order to get the specific results we need. I have a working example in this link if you want to see the complete implementation. In this example, I filter the result by user ID.

It's important to highlight the reference object only accepts one orberByChild function in the chain. That means that you can't use it twice to filter the subset by two different properties. If you want to do that, you need to add a property to the object which is a combination of the properties you want to filter.

For a complete reference of Angular Fire, use this link. For a complete reference of Firebase, use this link. Finally, for a complete list of querying functions, you can use this link.

If you found this post useful, please don't forget to press the like button and share it. If you are in doubt, don't hesitate to ask a question. As always, thank you for reading.

Firebase AngularJS Object (computer science) Database

Published at DZone with permission of Ezequiel Reyno. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Spelling “Equality” With IT: Addressing the Gender Gap in the Tech Industry
  • Building HIPAA Compliant APIs
  • Writing Beautiful, Optimized, and Better .NET Code With NDepend Static Analysis
  • Getting Started Building on the NEAR Network with Infura

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo