PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 2, 2022

[FIXED] How to create a composite index for boolean field in Firebase?

 November 02, 2022     firebase, google-cloud-firestore, indexing, php     No comments   

Issue

Im working with my PHP & Firebase project

I have this query code below in my PHP file

$query = $ref->orderBy('date', 'DESC')->where("isDeleted", "=", false);

This give me a Exception FailedPreconditionException and a message The query requires an index follow by a composite index link

  • I tried to copy & paste the link provided, but nothing happen.

  • So I try to create a index in firebase console manually, with the date as DESC and isDeleted as ASC and nothing happen.


Solution

The order of fields in an index does matter. orderBy() usually comes after other query constraints like isDeleted: false so the database has to order only those filtered entries. You can use the following index:

isDeleted ASC
date      ASC


Answered By - Dharmaraj
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing