Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase rest API filter query

my data look like

{
  "word0" : {
    "level" : "B2",
    "meaning" : [ "Meaning19", "meaning43" ],
    "type" : "Noun",
    "weight" : 0,
    "word" : "word99"
  },
  "word1" : {
    "level" : "C1",
    "meaning" : [ "Meaning19", "meaning43" ],
    "type" : "Noun",
    "weight" : 0,
    "word" : "word99"
  },
  "word10" : {
    "level" : "A2",
    "meaning" : [ "Meaning19", "meaning43" ],
    "type" : "Noun",
    "weight" : 0,
    "word" : "word99"
  }
}

i am using curl get request https://words-b6651.firebaseio.com/DE-EN.json?orderBy="$key"&print=pretty and i want to get all words of a given level

is it possible to do something like $key."level" as in MongoDB ? and how could i get these data

like image 790
FarFarAway Avatar asked Sep 28 '26 14:09

FarFarAway


1 Answers

You can order by a property using:

https://words-b6651.firebaseio.com/DE-EN.json?orderBy="level"&print=pretty

Two notes:

  • you'll need to add an index to your Firebase security rules: ".indexOn": "level"
  • the items in the JSON will be in an undetermined order, since JSON is inherently non-ordered. This means that ordering in the REST API is really only useful when you also filter the data, e.g.

    https://words-b6651.firebaseio.com/DE-EN.json?orderBy="level"&equalTo="B2"&print=pretty
    
like image 59
Frank van Puffelen Avatar answered Oct 01 '26 04:10

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!