0
votes

I am trying to get to know how i can map all collections inside of a collection. Because i am doing a like functionality. Inside of collections "posts" includes a lot of documents. Inside of those documents they have collections "likes".

so something likes this:

posts: [ {likes: ["#1231", "#1231"]} , {likes: ["#1231", "#1231"]} ]

in Firebase i want to take like the post collection and get all the of the collections of ever single document map then them the screen.

In express and MongoDB when you map every single document you have all the collections / arrays that you need (renders full results of every document) It does for you automatically, but i font know how it works with the Firebase.

any help?

If something isn't clear just comment.

1

1 Answers

0
votes

I guess you can do something like this :

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.getSubCollections = functions.https.onCall(async (data, context) => {

const docPath = data.docPath;

const collections = await admin.firestore().doc(docPath).listCollections();
const collectionIds = collections.map(col => col.id);

return { collections: collectionIds };

});

However, you may need an algorithm to retrieve all the Data you need.