Home > other >  how to order firebase firestore data by the field's value i.e. "reason" field name an
how to order firebase firestore data by the field's value i.e. "reason" field name an

Time:12-21

here is the firestore documen

I want to sort the data by the "reason" field's values like "spam" , "nudity" and other reasons. could you please help me with that.

CodePudding user response:

For version 8

yourdatabaseRef.where("reason", "==", "fieldNameProvided")

if you then want to order it just add

orderBy("parameter", "desc");

For Version 9

import { query, where, orderBy } from "firebase/firestore";  

const q = query(yourdatabaseRef, where("reason", "==", "fieldNameProvided"));

if you then want to order it, make a little change:

const q = query(yourdatabaseRef, where("reason", "==", "fieldNameProvided"), ("parameter", "desc"));

I hope this helps

  • Related