Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexes are not required for development unless you are using the REST API. - error using WebSocketConnection class #8488

Open
tonyhallett opened this issue Sep 7, 2024 · 3 comments

Comments

@tonyhallett
Copy link

tonyhallett commented Sep 7, 2024

Operating System

Windows 11

Environment (if applicable)

Version 128.0.6613.115 (Official Build) (64-bit)

Firebase SDK Version

^10.12.2

Firebase SDK Product(s)

Database

Project Tooling

React, typescript, parcel

Detailed Problem Description

I am iterating over a realtime database schema.
According to https://firebase.google.com/docs/database/security/indexing-data

Firebase allows you to do ad-hoc queries on your data using an arbitrary child key. If you know in advance what your indexes will be, you can define them via the .indexOn rule in your Firebase Realtime Database Security Rules to improve query performance.

Indexes are not required for development unless you are using the REST API.

So why am I receiving
Index not defined, add ".indexOn": "pNumber", for path "/things", to the rules
when the getOrderedByNumber callback is executed ?

Note that this also occurs with the emulator attached.

Steps and code to reproduce issue

export function DemoFiltering() {
  const rtb = useRTB();
  const thingsListRef = ref(rtb, "things");
  const orderByNumber = orderByChild("pNumber");
  const getOrderedByNumber = useCallback(
    async (constraint: QueryConstraint | undefined, info: string) => {
      let snapshot: DataSnapshot;
      let orderByNumberQuery: Query;
      try {
        if (constraint) {
          orderByNumberQuery = query(thingsListRef, constraint, orderByNumber);
        } else {
          orderByNumberQuery = query(thingsListRef, orderByNumber);
        }
        snapshot = await get(orderByNumberQuery);
      } catch (reason) {
          // `Index not defined, add ".indexOn": "pNumber", for path "/things", to the rules`
      }
   //.other code
@tonyhallett tonyhallett added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Sep 7, 2024
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: database needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Sep 9, 2024
@dlarocque
Copy link
Contributor

Thanks for submitting this issue @tonyhallett.

I found a commit that might have made orderByChild require an index to be defined: 2a5039e. This was introduced way back in 8.6.3.

@tonyhallett
Copy link
Author

I don't think that is related. This code is after the server has responded.
A quick search https://github.com/search?q=repo%3Afirebase%2Ffirebase-js-sdk+%22Index+not+defined%22&type=code has no code results of "Index not defined". Of course this could be created by an expression.

I will debug the server code to be sure that the error has come from there. If it has the question is why is it throwing when the docs state that we may index.

  return repo.server_.get(query).then(
    payload => {
      const node = nodeFromJSON(payload).withIndex(
        query._queryParams.getIndex()
      );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants