Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
906 views
in Technique[技术] by (71.8m points)

ios - Firebase .indexOn dynamic keys

I've started testing Firebase and I can't figure out one thing about indexing. I'm creating a structure based on what I've read on - Firebase Data Structuring - something like that example with Users and Groups. JSON tree looks something like this:

{
  "babies" : {
    "-KQSVCXI-ZMz_lQ_Q906" : {
      "name" : "Baby",
      "parents" : {
        "F0o8Gr5GC2SrakUYZpC20efcmk63" : true
      }
    },
    "-KQSf4t9XQC3LnbsxLYS" : {
      "name" : "Name2",
      "parents" : {
        "S6aO6Dx4lgg6anW9S9hu7EJrhVg1" : true
      }
    }
  }
}

and I'm trying to get babies for a parent - just like there were members in groups in a Firebase example. I'm doing that in the iOS Application by using:

self.babiesReference
                .queryOrderedByChild("parents/(user.uid)")
                .queryEqualToValue(true)
                .observeSingleEventOfType(.Value, withBlock: { (snapshot) in
                
                // Print value
                print(snapshot.value)
                
            }

where user.uid is current user's id. This works fine but the only problem that remains is this:

Using an unspecified index. Consider adding ".indexOn": "parents/S6aO6Dx4lgg6anW9S9hu7EJrhVg1" at /babies to your security rules for better performance

How to index this "dynamic" child presented by user's id? Is there a way to do it or must I change the tree structure?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...