skip to Main Content

I Am trying to create a node wrapper around my firebase function on a different server
technically using firebase as my main Database

And anytime I try to read using the default query function in the doc

const db = firebase-admin.firestore()
const data = await db.collection("cities").get()

Now instead of getting an array of objects like this

"_query": {
            "_firestore": {
                "projectId": "fir-demo-jd1"
            },
            "_queryOptions": {
                "parentPath": {
                    "segments": []
                },
                "collectionId": "bets",
                "converter": {},
                "allDescendants": false,
                "fieldFilters": [
                ],
                "fieldOrders": [
                ],
                "limit": null,
                "limitType": 0,
                "kindless": false,
                "requireConsistency": true
            },
            "_serializer": {
                "allowUndefined": false
            },
            "_allowUndefined": false
        },
        "_readTime": {
            "_seconds": 1676797103,
            "_nanoseconds": 433061000
        },
        "_size": 2,
        "_materializedDocs": null,
        "_materializedChanges": null
    },

What I want is to be able to see the list of country alone

As I woud later to use paganation also on the data thats like

.limit() with ease

2

Answers


  1. Chosen as BEST ANSWER

    So Apartly I have to map and convert it to JSON using this function

    const db = firebase-admin.firestore()
    const data = await db.collection("cities").get()
    console.log(docs.map((doc)=>doc.data()))
    

    I thought firebase handled all this under the hood


  2. db.collection("cities").get() returns a QuerySnapshot and from there you can loop over the DocumentSnapshots, as explained in the doc:

    const querySnapshot = await db.collection("cities").get();
    querySnapshot.forEach((doc) => {
        // doc.data() is never undefined for query doc snapshots
        console.log(doc.id, " => ", doc.data());
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search