Firestore can't get empty docs

Multi tool use
Multi tool use


Firestore can't get empty docs



I have collection of documents where the id of the doc is the users id.
Lets call these user documents.



Each "user document" contains a subcollection of chat messages. But not all "user documents" contains any fields (data, other than the subcollection).



I wan't to return all the doc in the collection that don't have any fields, but have a subcollection, but I seems this is not possible?


var allUserDocs = {},
count = 0,
users = firestore.collection("users");

users.get().then(snapshot => {
snapshot.forEach(doc => {
count++;
allUserDocs[count] = doc.data();
});

allUserDocs.count = count;
res.status(200).send(allUserDocs);
})



this code only returns the docs that contains fields, not the docs that only have a subcollection? Is there a way to return all?



How can i get a list of all document ids in the collection? both empty and non-empty ones? or how can I add a field to all the docs without fields if i cant access them?





I seems like their is a "showMissing" feature in the firestore API made to show all documents with no data. Bu can this flag be set on a nodejs collection query, so that the snapshot will show all empty docs? I need to get the path to all empty docs..
– mkelle
Jul 1 at 19:52




1 Answer
1



Use doc.id


doc.id


users.get().then(snapshot => {
snapshot.forEach(doc => {
count++;
allUserDocs[doc.id] = doc.data();
});

allUserDocs.count = count;
res.status(200).send(allUserDocs);
})





I already tried this, and i still only return the doc's which has any field defined. All other docs are ignored (even if they have a subcollection)
– mkelle
Jul 1 at 18:58





You could try to put at least one field in every doc, for instance hasNoMessages: true or maybe consider not using subcollections in the first place.
– Davide Valdo
Jul 2 at 21:54





PS It seems like you've set up a http endpoint to read a collection, I think that would be just an anti-pattern. The whole point is to cut intermediaries and ask for data directly to Firebase from the client.
– Davide Valdo
Jul 2 at 21:55






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

r698FYAvW bu4T47kXFz4BviGA9,K,U,AjCpNtaYRYrL9J1d4Z,MN0 57,gLGdTm4oYEa4J0WT5n vk4iG7SVSPY
0VHck,x7wWoHun 1Jnxyb7mVB61pys,QaLwIzzNDKyJxN XLR9Megu6S5kauj4yXo5YTCEbMoq EE4SICE17b,S7,2NvFAM7IrqrT

Popular posts from this blog

Rothschild family

Cinema of Italy