Firebase .indexOn dynamic keys

后端 未结 1 436
花落未央
花落未央 2020-12-19 14:53

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 - somethin

相关标签:
1条回答
  • 2020-12-19 15:52

    For this type of query (and in general when you get into requiring adding indexes dynamically) you'll likely need to set up an inverted index. In your case:

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

    This type of bidirectional linking is fairly common in Firebase (and in many similar NoSQL databases).

    0 讨论(0)
提交回复
热议问题