Firebase (2016) Shallow Query

前端 未结 2 1344
醉酒成梦
醉酒成梦 2020-11-27 22:33

I\'m trying out Firebase (since Google\'s new release).

In the original version of Firebase the parameter shallow=true would return an object with { key: true

相关标签:
2条回答
  • 2020-11-27 22:37

    The ?shallow=true parameter in Firebase Database 2.x was only available in the REST API. See https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-uri-params.

    In the new Firebase Database 3.x, the same parameter is still only available in the REST API. See https://firebase.google.com/docs/database/rest/retrieve-data#shallow

    You're using a Firebase SDK (JavaScript from the looks of it), which never supported this parameter.

    For more questions that have discussed this in the past, see:

    • Firebase retrieve child keys but not values
    • Firebase REST API working with shallow data
    • How do I do a shallow query on Firebase iOS?
    • Get Firebase child nodes' names without getting their children too in Firebase response?
    0 讨论(0)
  • 2020-11-27 22:43

    This worked for me based on Frank's answer:

    import request from 'request';
    
    request({ url: "https://[YOUR-APP-ID].firebaseio.com/path/to/data/.json?shallow=true" }, (error, response, body) => {
        const shallowData = JSON.parse(body);
        console.log(shallowData);
    });
    

    Reference: https://firebase.google.com/docs/database/rest/retrieve-data#shallow

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