How to search for a value in firebase Android

前端 未结 7 1841
孤城傲影
孤城傲影 2020-12-01 05:37

I am saving data as follows in the Firebase:

I want to find all records that have #Yahoo in their title. What will be the exact query for that?

I am

7条回答
  •  感情败类
    2020-12-01 06:33

    You cannot search for any item whose title contains #Yahoo. See: How to perform sql "LIKE" operation on firebase?

    You can however search items whose title begins with #Yahoo:

    Firebase firebase = new Firebase(Constants.FIREBASE_URL_USER_TASKS).child(Utils.encodeEmail(unProcessedEmail));
    
    Query queryRef = firebase.orderByChild("title").startAt("#" + mHashTag)
    

    To make this work well, you have to add an index to your Firebase rules:

    "rules": {
      "userTasks": {
        "$email": {
          ".indexOn": "title" // index tasks in their title property
        }
      }
    }
    

提交回复
热议问题