<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4" -->

---
title: Introducing Query-based Security Rules | daily.dev
description: Firebase Realtime Database introduces query-based security rules, letting developers restrict read access based on the properties of a query (such as...
canonical: https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Introducing Query-based Security Rules | daily.dev
og:description: Firebase Realtime Database introduces query-based security rules, letting developers restrict read access based on the properties of a query (such as...
og:url: https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4
og:image: https://api.daily.dev/og/posts/UIxCpRRR4.png
og:image:alt: Introducing Query-based Security Rules
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Introducing Query-based Security Rules

**[Firebase](https://daily.dev/sources/firebase-blog)** · 3 min read · 0 upvotes · 0 comments

## Summary

Firebase Realtime Database introduces query-based security rules, letting developers restrict read access based on the properties of a query (such as orderByKey, limitToFirst, orderByChild, equalTo, etc.) rather than only on data paths. This enables patterns like capping result set sizes or restricting reads to a user's own records without needing to nest data under a user id, simplifying data structures. Query expressions can be adopted incrementally alongside existing rules and are available immediately in the Firebase console and emulator.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://firebase.blog/posts/2018/01/introducing-query-based-security-rules>

## Questions this post answers

### How do I restrict Firebase Realtime Database reads based on query parameters like limitToFirst?

Firebase Realtime Database security rules support a query variable that lets you restrict reads based on properties of the issued query, such as orderByKey, orderByChild, limitToFirst, limitToLast, startAt, endAt, and equalTo. For example, a rule can require query.orderByKey and query.limitToFirst <= 100 so reads for more than 100 records fail.

_Explore more Firebase Realtime Database rule patterns and updates on daily.dev._

### How can I restrict Firebase Realtime Database reads to a user's own items without nesting data under their user id?

Use a query-based rule combining query.orderByChild == 'uid' and query.equalTo == auth.uid, along with checking auth.uid != null. This lets items be stored in a flat structure with a uid field rather than nested under each user's id, while still enforcing that a user can only query their own records; unauthorized queries simply fail.

_Developers simplifying database schemas can follow Firebase rule changes like this on daily.dev._

## Similar posts on daily.dev

- [Testing Firestore security rules without touching production](https://daily.dev/posts/testing-firestore-security-rules-without-touching-production-hniqyzuq6) · All Things Open · 1 upvotes · 0 comments
- [Authentication made easy: Building a secure e-commerce shopping cart with Firebase](https://daily.dev/posts/authentication-made-easy-building-a-secure-e-commerce-shopping-cart-with-firebase-pnlz7lysc) · Firebase · 0 upvotes · 0 comments
- [No Rules, No Locks: Firebase Misconfiguration and the Borrowers It Left Behind](https://daily.dev/posts/no-rules-no-locks-firebase-misconfiguration-and-the-borrowers-it-left-behind-dfdzx9pyz) · InfoSec Write-ups · 0 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#firebase](https://daily.dev/tags/firebase), [#authorization](https://daily.dev/tags/authorization)

[View this post on daily.dev](https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Introducing Query-based Security Rules","url":"https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4"},"datePublished":"2026-08-23T12:17:49.217Z","dateModified":"2026-08-23T12:25:37.948Z","description":"Firebase Realtime Database introduces query-based security rules, letting developers restrict read access based on the properties of a query (such as...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ed721de96163685d26ab7e314be3ebc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ed721de96163685d26ab7e314be3ebc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Firebase","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Firebase","logo":"https://media.daily.dev/image/upload/s--i395oqZH--/f_auto,q_auto/v1787487448/logos/firebase-blog?_a=BAMAMicg0","url":"https://daily.dev/sources/firebase-blog"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,firebase,authorization","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Firebase","item":"https://daily.dev/sources/firebase-blog"},{"@type":"ListItem","position":3,"name":"Introducing Query-based Security Rules"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/introducing-query-based-security-rules-uixcprrr4#faq","mainEntity":[{"@type":"Question","name":"How do I restrict Firebase Realtime Database reads based on query parameters like limitToFirst?","acceptedAnswer":{"@type":"Answer","text":"Firebase Realtime Database security rules support a query variable that lets you restrict reads based on properties of the issued query, such as orderByKey, orderByChild, limitToFirst, limitToLast, startAt, endAt, and equalTo. For example, a rule can require query.orderByKey and query.limitToFirst <= 100 so reads for more than 100 records fail. Explore more Firebase Realtime Database rule patterns and updates on daily.dev."}},{"@type":"Question","name":"How can I restrict Firebase Realtime Database reads to a user's own items without nesting data under their user id?","acceptedAnswer":{"@type":"Answer","text":"Use a query-based rule combining query.orderByChild == 'uid' and query.equalTo == auth.uid, along with checking auth.uid != null. This lets items be stored in a flat structure with a uid field rather than nested under each user's id, while still enforcing that a user can only query their own records; unauthorized queries simply fail. Developers simplifying database schemas can follow Firebase rule changes like this on daily.dev."}}]}
```

