Wildcard query on Firebase?

后端 未结 4 372
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 05:22

Is it possible to do wildcard queries on Firebase? For example:

https://foo.firebaseio.com/person.json?orderBy=\"name\"&equalTo=\"Lun*\"
4条回答
  •  遥遥无期
    2020-12-10 05:34

    I know it's been a while but I thought that others might be interested. You can "fake" a wildcard search for things like foo* (so basically you can search for values beginning with a specified string).

    For iOS & Swift it would look like this:

    dbReference.child("person").queryOrdered(byChild: "name").queryStarting(atValue: "foo").queryEnding(atValue: "foo\u{f8ff}").observe(.childAdded) { (snapshot: FIRDataSnapshot) in
        print("\(snapshot.key) - \(String(describing: snapshot.value))")
    }
    

    What this does is using a start and end values for name property where the end key is equal to the start + a very high code point in the Unicode range. Because it is after most regular characters in Unicode, the query matches all values that start with foo.

提交回复
热议问题